1 /* Tests of *printf for very large strings.
2 Copyright (C) 2000-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <array_length.h>
28 #include <libc-diag.h>
33 "C", "de_DE.ISO-8859-1", "de_DE.UTF-8", "ja_JP.EUC-JP"
48 strcpy (buf
, "/tmp/test-vfprintfXXXXXX");
52 printf ("cannot open temporary file: %m\n");
57 for (i
= 0; i
< array_length (locs
); ++i
)
63 setlocale (LC_ALL
, locs
[i
]);
65 memset (large
, '\1', sizeof (large
));
66 large
[sizeof (large
) - 1] = '\0';
71 printf ("cannot dup for locale %s: %m\n",
72 setlocale (LC_ALL
, NULL
));
76 if (ftruncate (fd2
, 0) != 0)
78 printf ("cannot truncate file for locale %s: %m\n",
79 setlocale (LC_ALL
, NULL
));
83 fp
= fdopen (fd2
, "a");
86 printf ("cannot create FILE for locale %s: %m\n",
87 setlocale (LC_ALL
, NULL
));
91 fprintf (fp
, "%s", large
);
92 fprintf (fp
, "%.*s", 30000, large
);
94 /* We're testing a large format string here and need to generate it
95 to avoid this source file being ridiculous. So disable the warning
96 about a generated format string. */
97 DIAG_PUSH_NEEDS_COMMENT
;
98 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat-security");
100 DIAG_POP_NEEDS_COMMENT
;
101 fprintf (fp
, "%-1.300000000s", "hello");
103 if (fflush (fp
) != 0 || ferror (fp
) != 0 || fclose (fp
) != 0)
105 printf ("write error for locale %s: %m\n",
106 setlocale (LC_ALL
, NULL
));
110 if (fstat (fd
, &st
) != 0)
112 printf ("cannot stat for locale %s: %m\n",
113 setlocale (LC_ALL
, NULL
));
116 else if (st
.st_size
!= 50000 + 30000 + 19999 + 5)
118 printf ("file size incorrect for locale %s: %jd instead of %jd\n",
119 setlocale (LC_ALL
, NULL
),
120 (intmax_t) st
.st_size
,
121 (intmax_t) 50000 + 30000 + 19999 + 5);
125 printf ("locale %s OK\n", setlocale (LC_ALL
, NULL
));
133 #define TEST_FUNCTION do_test ()
134 #include "../test-skeleton.c"