Fix hypot handling of subnormals (bug 16316, bug 16330).
[glibc.git] / stdio-common / test-vfprintf.c
blob3490f62e333ade8c15a6ad0c6c9699a8dec83b96
1 /* Tests of *printf for very large strings.
2 Copyright (C) 2000-2013 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, see
18 <http://www.gnu.org/licenses/>. */
20 #include <locale.h>
21 #include <mcheck.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <sys/stat.h>
30 const char *locs[] =
32 "C", "de_DE.ISO-8859-1", "de_DE.UTF-8", "ja_JP.EUC-JP"
34 #define nlocs (sizeof (locs) / sizeof (locs[0]))
37 char large[50000];
39 int
40 main (void)
42 char buf[25];
43 size_t i;
44 int res = 0;
45 int fd;
47 mtrace ();
49 strcpy (buf, "/tmp/test-vfprintfXXXXXX");
50 fd = mkstemp (buf);
51 if (fd == -1)
53 printf ("cannot open temporary file: %m\n");
54 exit (1);
56 unlink (buf);
58 for (i = 0; i < nlocs; ++i)
60 FILE *fp;
61 struct stat st;
62 int fd2;
64 setlocale (LC_ALL, locs[i]);
66 memset (large, '\1', sizeof (large));
67 large[sizeof (large) - 1] = '\0';
69 fd2 = dup (fd);
70 if (fd2 == -1)
72 printf ("cannot dup for locale %s: %m\n",
73 setlocale (LC_ALL, NULL));
74 exit (1);
77 if (ftruncate (fd2, 0) != 0)
79 printf ("cannot truncate file for locale %s: %m\n",
80 setlocale (LC_ALL, NULL));
81 exit (1);
84 fp = fdopen (fd2, "a");
85 if (fp == NULL)
87 printf ("cannot create FILE for locale %s: %m\n",
88 setlocale (LC_ALL, NULL));
89 exit (1);
92 fprintf (fp, "%s", large);
93 fprintf (fp, "%.*s", 30000, large);
94 large[20000] = '\0';
95 fprintf (fp, large);
96 fprintf (fp, "%-1.300000000s", "hello");
98 if (fflush (fp) != 0 || ferror (fp) != 0 || fclose (fp) != 0)
100 printf ("write error for locale %s: %m\n",
101 setlocale (LC_ALL, NULL));
102 exit (1);
105 if (fstat (fd, &st) != 0)
107 printf ("cannot stat for locale %s: %m\n",
108 setlocale (LC_ALL, NULL));
109 exit (1);
111 else if (st.st_size != 50000 + 30000 + 19999 + 5)
113 printf ("file size incorrect for locale %s: %jd instead of %jd\n",
114 setlocale (LC_ALL, NULL),
115 (intmax_t) st.st_size,
116 (intmax_t) 50000 + 30000 + 19999 + 5);
117 res = 1;
119 else
120 printf ("locale %s OK\n", setlocale (LC_ALL, NULL));
123 close (fd);
125 return res;