5 static wchar_t buf
[100];
6 #define nbuf (sizeof (buf) / sizeof (buf[0]))
12 { nbuf
, "hello world", 11 },
13 { 0, "hello world", -1 },
20 main(int argc
, char *argv
[])
26 n
= swprintf(buf
, nbuf
,L
"Hello %s" , "world");
29 printf ("incorrect return value: %zd instead of 11\n", n
);
32 else if (wcscmp(buf
, L
"Hello world") != 0)
34 printf("incorrect string: L\"%ls\" instead of L\"Hello world\"\n", buf
);
38 n
= swprintf(buf
, nbuf
, L
"Is this >%g< 3.1?", 3.1);
40 printf("incorrect return value: %zd instead of 18\n", n
);
42 } else if (wcscmp (buf
, L
"Is this >3.1< 3.1?") != 0) {
43 printf("incorrect string: L\"%ls\" instead of L\"Is this >3.1< 3.1?\"\n",
48 for (n
= 0; n
< sizeof(tests
) / sizeof(tests
[0]); ++n
) {
49 ssize_t res
= swprintf(buf
, tests
[n
].n
, L
"%s", tests
[n
].str
);
51 if (tests
[n
].exp
< 0 && res
>= 0) {
52 printf("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to fail\n",
53 tests
[n
].n
, tests
[n
].str
);
55 } else if (tests
[n
].exp
>= 0 && tests
[n
].exp
!= res
) {
56 printf("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to return %Zd, but got %Zd\n",
57 tests
[n
].n
, tests
[n
].str
, tests
[n
].exp
, res
);
60 printf("swprintf (buf, %Zu, L\"%%s\", \"%s\") OK\n", tests
[n
].n
,
65 if (swprintf(buf
, nbuf
, L
"%.0s", "foo") != 0 || wcslen(buf
) != 0) {
66 printf("swprintf (buf, %Zu, L\"%%.0s\", \"foo\") create some output\n",
71 if (swprintf(buf
, nbuf
, L
"%.0ls", L
"foo") != 0 || wcslen(buf
) != 0) {
72 printf("swprintf (buf, %Zu, L\"%%.0ls\", L\"foo\") create some output\n",