tst-getdate: Improve testcase flexibility and add test.
[glibc.git] / stdio-common / bug22.c
blob029b54994157e8388d4f976736b13634ed821b41
1 /* BZ #5424 */
2 #include <stdio.h>
3 #include <errno.h>
4 #include <libc-diag.h>
6 /* INT_MAX + 1 */
7 #define N 2147483648
9 /* (INT_MAX / 2) + 2 */
10 #define N2 1073741825
12 /* INT_MAX - 3 */
13 #define N3 2147483644
15 #define STRINGIFY(S) #S
16 #define MAKE_STR(S) STRINGIFY(S)
18 #define SN MAKE_STR(N)
19 #define SN2 MAKE_STR(N2)
20 #define SN3 MAKE_STR(N3)
22 static int
23 do_test (void)
25 int ret;
27 FILE *fp = fopen ("/dev/null", "w");
28 if (fp == NULL)
30 puts ("cannot open /dev/null");
31 return 1;
34 /* GCC 9 warns about output of more than INT_MAX characters; this is
35 deliberately tested here. */
36 DIAG_PUSH_NEEDS_COMMENT;
37 #if __GNUC_PREREQ (7, 0)
38 DIAG_IGNORE_NEEDS_COMMENT (9, "-Wformat-overflow=");
39 #endif
40 ret = fprintf (fp, "%" SN "d", 1);
41 DIAG_POP_NEEDS_COMMENT;
42 printf ("ret = %d\n", ret);
43 if (ret != -1 || errno != EOVERFLOW)
44 return 1;
46 /* GCC 9 warns about output of more than INT_MAX characters; this is
47 deliberately tested here. */
48 DIAG_PUSH_NEEDS_COMMENT;
49 #if __GNUC_PREREQ (7, 0)
50 DIAG_IGNORE_NEEDS_COMMENT (9, "-Wformat-overflow=");
51 #endif
52 ret = fprintf (fp, "%." SN "d", 1);
53 DIAG_POP_NEEDS_COMMENT;
54 printf ("ret = %d\n", ret);
55 if (ret != -1 || errno != EOVERFLOW)
56 return 1;
58 ret = fprintf (fp, "%." SN3 "d", 1);
59 printf ("ret = %d\n", ret);
60 if (ret != N3)
61 return 1;
63 /* GCC 9 warns about output of more than INT_MAX characters; this is
64 deliberately tested here. */
65 DIAG_PUSH_NEEDS_COMMENT;
66 #if __GNUC_PREREQ (7, 0)
67 DIAG_IGNORE_NEEDS_COMMENT (9, "-Wformat-overflow=");
68 #endif
69 ret = fprintf (fp, "%" SN2 "d%" SN2 "d", 1, 1);
70 DIAG_POP_NEEDS_COMMENT;
71 printf ("ret = %d\n", ret);
73 return ret != -1 || errno != EOVERFLOW;
76 #define TIMEOUT 60
77 #define TEST_FUNCTION do_test ()
78 #include "../test-skeleton.c"