Clean up __exit_thread.
[glibc.git] / stdio-common / tst-sprintf.c
blobc4e911fe94db2d174a0b05f1d890800d688aa2b8
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <locale.h>
4 #include <string.h>
7 int
8 main (void)
10 char buf[100];
11 int result = 0;
13 if (sprintf (buf, "%.0ls", L"foo") != 0
14 || strlen (buf) != 0)
16 puts ("sprintf (buf, \"%.0ls\", L\"foo\") produced some output");
17 result = 1;
20 #define SIZE (1024*70000)
21 #define STR(x) #x
23 char *dst = malloc (SIZE + 1);
25 if (dst == NULL)
27 puts ("memory allocation failure");
28 result = 1;
30 else
32 sprintf (dst, "%*s", SIZE, "");
33 if (strnlen (dst, SIZE + 1) != SIZE)
35 puts ("sprintf (dst, \"%*s\", " STR(SIZE) ", \"\") did not produce enough output");
36 result = 1;
38 free (dst);
41 if (sprintf (buf, "%1$d%3$.*2$s%4$d", 7, 67108863, "x", 8) != 3
42 || strcmp (buf, "7x8") != 0)
44 printf ("sprintf (buf, \"%%1$d%%3$.*2$s%%4$d\", 7, 67108863, \"x\", 8) produced `%s' output", buf);
45 result = 1;
48 if (sprintf (buf, "%67108863.16\"%d", 7) != 14
49 || strcmp (buf, "%67108863.16\"7") != 0)
51 printf ("sprintf (buf, \"%%67108863.16\\\"%%d\", 7) produced `%s' output", buf);
52 result = 1;
55 if (sprintf (buf, "%*\"%d", 0x3ffffff, 7) != 11
56 || strcmp (buf, "%67108863\"7") != 0)
58 printf ("sprintf (buf, \"%%*\\\"%%d\", 0x3ffffff, 7) produced `%s' output", buf);
59 result = 1;
62 if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
64 puts ("cannot set locale");
65 result = 1;
67 else if (sprintf (buf, "%.8s\n", "Foo: \277") != 7
68 || strcmp (buf, "Foo: \277\n") != 0)
70 printf ("sprintf (buf, \"%%.8s\\n\", \"Foo: \\277\") produced '%s' output\n", buf);
71 result = 1;
74 return result;