6 static wchar_t buf
[100];
7 #define nbuf (sizeof (buf) / sizeof (buf[0]))
15 { nbuf
, "hello world", 11 },
16 { 0, "hello world", -1 },
22 main (int argc
, char *argv
[])
28 n
= swprintf (buf
, nbuf
, L
"Hello %s", "world");
31 printf ("incorrect return value: %zd instead of 11\n", n
);
34 else if (wcscmp (buf
, L
"Hello world") != 0)
36 printf ("incorrect string: L\"%ls\" instead of L\"Hello world\"\n", buf
);
41 n
= swprintf (buf
, nbuf
, L
"Is this >%g< 3.1?", 3.1);
44 printf ("incorrect return value: %zd instead of 18\n", n
);
47 else if (wcscmp (buf
, L
"Is this >3.1< 3.1?") != 0)
49 printf ("incorrect string: L\"%ls\" instead of L\"Is this >3.1< 3.1?\"\n",
54 for (n
= 0; n
< sizeof (tests
) / sizeof (tests
[0]); ++n
)
56 ssize_t res
= swprintf (buf
, tests
[n
].n
, L
"%s", tests
[n
].str
);
58 if (tests
[n
].exp
< 0 && res
>= 0)
60 printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to fail\n",
61 tests
[n
].n
, tests
[n
].str
);
64 else if (tests
[n
].exp
>= 0 && tests
[n
].exp
!= res
)
66 printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to return %Zd, but got %Zd\n",
67 tests
[n
].n
, tests
[n
].str
, tests
[n
].exp
, res
);
71 printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") OK\n",
72 tests
[n
].n
, tests
[n
].str
);
75 if (swprintf (buf
, nbuf
, L
"%.0s", "foo") != 0
78 printf ("swprintf (buf, %Zu, L\"%%.0s\", \"foo\") create some output\n",
83 if (swprintf (buf
, nbuf
, L
"%.0ls", L
"foo") != 0
86 printf ("swprintf (buf, %Zu, L\"%%.0ls\", L\"foo\") create some output\n",