12 main (int argc
, char *argv
[])
16 char name
[] = "/tmp/wprintf.out.XXXXXX";
24 error (EXIT_FAILURE
, errno
, "cannot open temporary file");
28 setlocale (LC_ALL
, "en_US.UTF-8");
30 fp
= fdopen (dup (fd
), "w");
32 error (EXIT_FAILURE
, errno
, "fdopen(,\"w\")");
34 fwprintf (fp
, L
"test start");
35 fwprintf (fp
, L
" int %d\n", a
);
37 /* String with precision. */
38 fwprintf (fp
, L
"1[%6.3s]\n", argv
[1]);
42 fp
= fdopen (dup (fd
), "a");
44 error (EXIT_FAILURE
, errno
, "fdopen(,\"a\")");
46 setvbuf (fp
, NULL
, _IONBF
, 0);
48 /* fwprintf to unbuffered stream. */
49 fwprintf (fp
, L
"hello.\n");
54 /* Now read it back in. This time using multibyte functions. */
55 lseek (fd
, SEEK_SET
, 0);
56 fp
= fdopen (fd
, "r");
58 error (EXIT_FAILURE
, errno
, "fdopen(,\"r\")");
60 if (fgets (buf
, sizeof buf
, fp
) != buf
)
61 error (EXIT_FAILURE
, errno
, "first fgets");
63 if (buf
[len
- 1] == '\n')
67 puts ("newline missing after first line");
70 printf ("1st line: \"%.*s\" -> %s\n", (int) len
, buf
,
71 strncmp (buf
, "test start int 3", len
) == 0 ? "OK" : "FAIL");
72 res
|= strncmp (buf
, "test start int 3", len
) != 0;
74 if (fgets (buf
, sizeof buf
, fp
) != buf
)
75 error (EXIT_FAILURE
, errno
, "second fgets");
77 if (buf
[len
- 1] == '\n')
81 puts ("newline missing after second line");
84 printf ("2nd line: \"%.*s\" -> %s\n", (int) len
, buf
,
85 strncmp (buf
, "1[ Som]", len
) == 0 ? "OK" : "FAIL");
86 res
|= strncmp (buf
, "1[ Som]", len
) != 0;
88 if (fgets (buf
, sizeof buf
, fp
) != buf
)
89 error (EXIT_FAILURE
, errno
, "third fgets");
91 if (buf
[len
- 1] == '\n')
95 puts ("newline missing after third line");
98 printf ("3rd line: \"%.*s\" -> %s\n", (int) len
, buf
,
99 strncmp (buf
, "hello.", len
) == 0 ? "OK" : "FAIL");
100 res
|= strncmp (buf
, "hello.", len
) != 0;