1 /* Tests of *printf for very large strings.
2 Copyright (C) 2000, 2002, 2003, 2007 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
33 "C", "de_DE.ISO-8859-1", "de_DE.UTF-8", "ja_JP.EUC-JP"
35 #define nlocs (sizeof (locs) / sizeof (locs[0]))
50 strcpy (buf
, "/tmp/test-vfprintfXXXXXX");
54 printf ("cannot open temporary file: %m\n");
59 for (i
= 0; i
< nlocs
; ++i
)
65 setlocale (LC_ALL
, locs
[i
]);
67 memset (large
, '\1', sizeof (large
));
68 large
[sizeof (large
) - 1] = '\0';
73 printf ("cannot dup for locale %s: %m\n",
74 setlocale (LC_ALL
, NULL
));
78 if (ftruncate (fd2
, 0) != 0)
80 printf ("cannot truncate file for locale %s: %m\n",
81 setlocale (LC_ALL
, NULL
));
85 fp
= fdopen (fd2
, "a");
88 printf ("cannot create FILE for locale %s: %m\n",
89 setlocale (LC_ALL
, NULL
));
93 fprintf (fp
, "%s", large
);
94 fprintf (fp
, "%.*s", 30000, large
);
97 fprintf (fp
, "%-1.300000000s", "hello");
99 if (fflush (fp
) != 0 || ferror (fp
) != 0 || fclose (fp
) != 0)
101 printf ("write error for locale %s: %m\n",
102 setlocale (LC_ALL
, NULL
));
106 if (fstat (fd
, &st
) != 0)
108 printf ("cannot stat for locale %s: %m\n",
109 setlocale (LC_ALL
, NULL
));
112 else if (st
.st_size
!= 50000 + 30000 + 19999 + 5)
114 printf ("file size incorrect for locale %s: %jd instead of %jd\n",
115 setlocale (LC_ALL
, NULL
),
116 (intmax_t) st
.st_size
,
117 (intmax_t) 50000 + 30000 + 19999 + 5);
121 printf ("locale %s OK\n", setlocale (LC_ALL
, NULL
));