* sysdeps/powerpc/powerpc32/elf/start.S: Ensure .data is non-empty.
[glibc/pb-stable.git] / stdio-common / tst-sprintf.c
blobc04fef18f4b14cc22943a71985e00fcbb45e22fb
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
6 int
7 main (void)
9 char buf[100];
10 int result = 0;
12 if (sprintf (buf, "%.0ls", L"foo") != 0
13 || strlen (buf) != 0)
15 puts ("sprintf (buf, \"%.0ls\", L\"foo\") produced some output");
16 result = 1;
19 #define SIZE (1024*70000)
20 #define STR(x) #x
22 char *dst = malloc (SIZE + 1);
24 if (dst == NULL)
26 puts ("memory allocation failure");
27 result = 1;
29 else
31 sprintf (dst, "%*s", SIZE, "");
32 if (strnlen (dst, SIZE + 1) != SIZE)
34 puts ("sprintf (dst, \"%*s\", " STR(SIZE) ", \"\") did not produce enough output");
35 result = 1;
37 free (dst);
40 if (sprintf (buf, "%1$d%3$.*2$s%4$d", 7, 67108863, "x", 8) != 3
41 || strcmp (buf, "7x8") != 0)
43 printf ("sprintf (buf, \"%%1$d%%3$.*2$s%%4$d\", 7, 67108863, \"x\", 8) produced `%s' output", buf);
44 result = 1;
47 if (sprintf (buf, "%67108863.16\"%d", 7) != 14
48 || strcmp (buf, "%67108863.16\"7") != 0)
50 printf ("sprintf (buf, \"%%67108863.16\\\"%%d\", 7) produced `%s' output", buf);
51 result = 1;
54 if (sprintf (buf, "%*\"%d", 0x3ffffff, 7) != 11
55 || strcmp (buf, "%67108863\"7") != 0)
57 printf ("sprintf (buf, \"%%*\\\"%%d\", 0x3ffffff, 7) produced `%s' output", buf);
58 result = 1;
61 return result;