1 /* Taken from the Li18nux base test suite. */
3 #define _XOPEN_SOURCE 500
11 #define WIDE_STR_LEN 32
14 main (int argc
, char *argv
[])
18 wchar_t *ret
, wcs
[WIDE_STR_LEN
];
20 const char il_str1
[] = {0xe3, 0x81, '\0'};
21 const char il_str2
[] = {'0', '\n', 'A', 'B', 0xe3, 0x81, 'E', '\0'};
22 char name1
[] = "/tmp/tst-fgetws.out.XXXXXX";
23 char name2
[] = "/tmp/tst-fgetws.out.XXXXXX";
26 puts ("This program runs on de_DE.UTF-8 locale.");
27 if (setlocale (LC_ALL
, "de_DE.UTF-8") == NULL
)
29 fprintf (stderr
, "Err: Cannot run on the de_DE.UTF-8 locale");
33 /* Make a file `il_str1'. */
37 printf ("cannot open temp file: %m\n");
40 if ((fp
= fdopen (fd
, "w")) == NULL
)
42 printf ("Can't open %s.\n", argv
[1]);
45 fwrite (il_str1
, sizeof (char), sizeof (il_str1
), fp
);
48 /* Make a file `il_str2'. */
52 printf ("cannot open temp file: %m\n");
55 if ((fp
= fdopen (fd
, "w")) == NULL
)
57 fprintf (stderr
, "Can't open %s.\n", argv
[1]);
60 fwrite (il_str2
, sizeof (char), sizeof (il_str2
), fp
);
64 /* Test for il_str1. */
65 if ((fp
= fopen (name1
, "r")) == NULL
)
67 fprintf (stderr
, "Can't open %s.\n", argv
[1]);
72 puts ("Read a byte sequence which is invalid as a wide character string.");
73 puts (" bytes: 0xe3, 0x81, '\\0'");
76 ret
= fgetws (wcs
, WIDE_STR_LEN
, fp
);
80 puts ("Return Value: NULL");
83 puts ("errno = EILSEQ");
86 printf ("errno = %d\n", errno
);
92 printf ("Return Value: %p\n", ret
);
93 for (i
= 0; i
< wcslen (wcs
) + 1; i
++)
94 printf (" wcs[%zd] = %04x", i
, (unsigned int)wcs
[i
]);
99 /* Test for il_str2. */
100 if ((fp
= fopen (name2
, "r")) == NULL
)
102 fprintf (stderr
, "Can't open %s.\n", argv
[1]);
107 puts ("Read a byte sequence which is invalid as a wide character string.");
108 puts (" bytes: '0', '\\n', 'A', 'B', 0xe3, 0x81, 'c', '\\0'");
111 ret
= fgetws (wcs
, WIDE_STR_LEN
, fp
);
115 puts ("Return Value: NULL");
118 puts ("errno = EILSEQ");
120 printf ("errno = %d\n", errno
);
128 printf ("Return Value: %p\n", ret
);
129 for (i
= 0; i
< wcslen (wcs
) + 1; i
++)
130 printf (" wcs[%zd] = 0x%04x", i
, (unsigned int)wcs
[i
]);
133 for (i
= 0; il_str2
[i
] != '\n'; ++i
)
134 if ((wchar_t) il_str2
[i
] != wcs
[i
])
136 puts ("read string not correct");
140 if (il_str2
[i
] == '\n')
144 puts ("newline missing");
147 else if (wcs
[i
+ 1] != L
'\0')
149 puts ("read string not NUL-terminated");
155 puts ("\nsecond line");
157 ret
= fgetws (wcs
, WIDE_STR_LEN
, fp
);
161 puts ("Return Value: NULL");
164 puts ("errno = EILSEQ");
167 printf ("errno = %d\n", errno
);
173 printf ("Return Value: %p\n", ret
);
174 for (i
= 0; i
< wcslen (wcs
) + 1; i
++)
175 printf (" wcs[%zd] = 0x%04x", i
, (unsigned int)wcs
[i
]);