• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // decode across buffer boundary
2 #include <stdio.h>
3 #include <locale.h>
4 #include <wchar.h>
5 #include <unistd.h>
6 #include <errno.h>
7 #include <string.h>
8 #include "test.h"
9 
10 #define A(c) do { if (!(c)) t_error(#c" failed\n"); } while(0)
11 
main()12 int main()
13 {
14 	t_setutf8();
15 
16 	int p[2];
17 	A(pipe(p) == 0);
18 	A(write(p[1], "x\340\240", 3) == 3);
19 	A(dup2(p[0], 0) == 0);
20 	wint_t wc;
21 	wc = fgetwc(stdin);
22 	A(wc == 'x');
23 	A(write(p[1], "\200", 1) == 1);
24 	close(p[1]);
25 
26 	wc = fgetwc(stdin);
27 	if (wc != 0x800)
28 		t_error("wanted 0x800, got 0x%x\n", (unsigned)wc);
29 
30 	errno = 0;
31 	wc = fgetwc(stdin);
32 	if (wc != WEOF)
33 		t_error("wanted WEOF, got 0x%x\n", (unsigned)wc);
34 	if (errno != 0)
35 		t_error("wanted errno==0, got %d (%s)\n", errno, strerror(errno));
36 	A(feof(stdin)!=0);
37 	A(ferror(stdin)==0);
38 	return t_status;
39 }
40