functional: add mntent test
[libc-test.git] / src / regression / fgetwc-buffering.c
blobdc0a13d041303a1f29443556676316211da7af7e
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"
10 #define A(c) do { if (!(c)) t_error(#c" failed\n"); } while(0)
12 int main()
14 t_setutf8();
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]);
26 wc = fgetwc(stdin);
27 if (wc != 0x800)
28 t_error("wanted 0x800, got 0x%x\n", (unsigned)wc);
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;