1 /* Test case by Yoshito Kawada <KAWADA@jp.ibm.com>. */
13 main (int argc, char *argv[])
17 char name[] = "/tmp/wprintf.out.XXXXXX";
25 error (EXIT_FAILURE, errno, "cannot open temporary file");
29 setlocale (LC_ALL, "");
31 fp = fdopen (dup (fd), "w");
33 error (EXIT_FAILURE, errno, "fdopen(,\"w\")");
35 fwprintf (fp, L"test start");
36 fwprintf (fp, L" int %d\n", a);
38 /* String with precision. */
39 fwprintf (fp, L"1[%6.3s]\n", argv[1]);
43 fp = fdopen (dup (fd), "a");
45 error (EXIT_FAILURE, errno, "fdopen(,\"a\")");
47 setvbuf (fp, NULL, _IONBF, 0);
49 /* fwprintf to unbuffered stream. */
50 fwprintf (fp, L"hello.\n");
55 /* Now read it back in. This time using multibyte functions. */
56 lseek (fd, SEEK_SET, 0);
57 fp = fdopen (fd, "r");
59 error (EXIT_FAILURE, errno, "fdopen(,\"r\")");
61 if (fgets (buf, sizeof buf, fp) != buf)
62 error (EXIT_FAILURE, errno, "first fgets");
64 if (buf[len - 1] == '\n')
68 puts ("newline missing after first line");
71 printf ("1st line: \"%.*s\" -> %s\n", (int) len, buf,
72 strncmp (buf, "test start int 3", len) == 0 ? "OK" : "FAIL");
73 res |= strncmp (buf, "test start int 3", len) != 0;
75 if (fgets (buf, sizeof buf, fp) != buf)
76 error (EXIT_FAILURE, errno, "second fgets");
78 if (buf[len - 1] == '\n')
82 puts ("newline missing after second line");
85 printf ("2nd line: \"%.*s\" -> %s\n", (int) len, buf,
86 strncmp (buf, "1[ Som]", len) == 0 ? "OK" : "FAIL");
87 res |= strncmp (buf, "1[ Som]", len) != 0;
89 if (fgets (buf, sizeof buf, fp) != buf)
90 error (EXIT_FAILURE, errno, "third fgets");
92 if (buf[len - 1] == '\n')
96 puts ("newline missing after third line");
99 printf ("3rd line: \"%.*s\" -> %s\n", (int) len, buf,
100 strncmp (buf, "hello.", len) == 0 ? "OK" : "FAIL");
101 res |= strncmp (buf, "hello.", len) != 0;