1 /* Test case by Yoshito Kawada <KAWADA@jp.ibm.com>. */
12 void error(int exitCode
, int, const char* message
);
16 main(int argc
, char *argv
[])
20 char name
[] = "/tmp/wprintf.out.XXXXXX";
28 error(EXIT_FAILURE
, errno
, "cannot open temporary file");
32 setlocale(LC_ALL
, "");
34 fp
= fdopen(dup(fd
), "w");
36 error(EXIT_FAILURE
, errno
, "fdopen(,\"w\")");
38 fwprintf(fp
,L
"test start" );
39 fwprintf(fp
, L
" int %d\n", a
);
41 /* String with precision. */
42 fwprintf(fp
, L
"1[%6.3s]\n", argv
[1]);
46 fp
= fdopen(dup (fd
), "a");
48 error(EXIT_FAILURE
, errno
, "fdopen(,\"a\")");
50 setvbuf(fp
, NULL
, _IONBF
, 0);
52 /* fwprintf to unbuffered stream. */
53 fwprintf(fp
, L
"hello.\n");
57 /* Now read it back in. This time using multibyte functions. */
58 lseek(fd
, SEEK_SET
, 0);
61 error(EXIT_FAILURE
, errno
, "fdopen(,\"r\")");
63 if (fgets(buf
, sizeof buf
, fp
) != buf
)
64 error(EXIT_FAILURE
, errno
, "first fgets");
66 if (buf
[len
- 1] == '\n')
69 puts ("newline missing after first line");
72 printf("1st line: \"%.*s\" -> %s\n", (int) len
, buf
,
73 strncmp(buf
, "test start int 3", len
) == 0 ? "OK" : "FAIL");
74 res
|= strncmp(buf
, "test start int 3", len
) != 0;
76 if (fgets(buf
, sizeof(buf
), fp
) != buf
)
77 error(EXIT_FAILURE
, errno
, "second fgets");
79 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')
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;
107 error(int exitCode
, int errorCode
, const char* message
)