Use size_t for string length variable.
[glibc/history.git] / stdio-common / tst-swprintf.c
blobe65234b1c2f243d34c4de4e78f6768f2863bda1c
1 #include <locale.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <wchar.h>
6 /* This is the relevant piece from the charmap:
7 <UFF61> /x8e/xa1 HALFWIDTH IDEOGRAPHIC FULL STOP
8 <UFF62> /x8e/xa2 HALFWIDTH LEFT CORNER BRACKET
9 <UFF63> /x8e/xa3 HALFWIDTH RIGHT CORNER BRACKET
10 <UFF64> /x8e/xa4 HALFWIDTH IDEOGRAPHIC COMMA
13 const char input[] = "\x8e\xa1g\x8e\xa2h\x8e\xa3i\x8e\xa4j";
15 int
16 main (void)
18 wchar_t buf[1000];
19 #define nbuf (sizeof (buf) / sizeof (buf[0]))
20 int result = 0;
21 ssize_t n;
23 if (setlocale (LC_ALL, "ja_JP.EUC-JP") == NULL)
25 puts ("cannot set locale");
26 exit (1);
29 #define CHECK(fmt, nexp, exp) \
30 n = swprintf (buf, nbuf, fmt, input); \
31 if (n != nexp) \
32 { \
33 printf ("swprintf (.., .., L\"%ls\", \"%ls\") return %d, not %d\n", \
34 fmt, (wchar_t*) input, (int) n, (int) nexp); \
35 result = 1; \
36 } \
37 else if (wcscmp (buf, exp) != 0) \
38 { \
39 printf ("\
40 swprintf (.., .., L\"%ls\", \"%ls\") produced \"%ls\", not \"%ls\"\n", \
41 fmt, (wchar_t *) input, buf, exp ); \
42 result = 1; \
45 CHECK (L"[%-6.0s]", 8, L"[ ]");
46 CHECK (L"[%-6.1s]", 8, L"[\xff61 ]");
47 CHECK (L"[%-6.2s]", 8, L"[\xff61g ]");
48 CHECK (L"[%-6.3s]", 8, L"[\xff61g\xff62 ]");
49 CHECK (L"[%-6.4s]", 8, L"[\xff61g\xff62h ]");
50 CHECK (L"[%-6.5s]", 8, L"[\xff61g\xff62h\xff63 ]");
51 CHECK (L"[%-6.6s]", 8, L"[\xff61g\xff62h\xff63i]");
52 CHECK (L"[%-6.7s]", 9, L"[\xff61g\xff62h\xff63i\xff64]");
53 CHECK (L"[%-6.8s]", 10, L"[\xff61g\xff62h\xff63i\xff64j]");
55 return result;