1 /* Test of POSIX compatible printf() function.
2 Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
23 #if HAVE_GETRLIMIT && HAVE_SETRLIMIT
26 #include <sys/types.h>
28 #include <sys/resource.h>
33 main (int argc, char *argv[])
39 /* Some printf implementations allocate temporary space with malloc. */
40 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
42 if (getrlimit (RLIMIT_DATA, &limit) < 0)
44 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
45 limit.rlim_max = 5000000;
46 limit.rlim_cur = limit.rlim_max;
47 if (setrlimit (RLIMIT_DATA, &limit) < 0)
50 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
52 if (getrlimit (RLIMIT_AS, &limit) < 0)
54 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
55 limit.rlim_max = 5000000;
56 limit.rlim_cur = limit.rlim_max;
57 if (setrlimit (RLIMIT_AS, &limit) < 0)
60 /* Some printf implementations allocate temporary space on the stack. */
62 if (getrlimit (RLIMIT_STACK, &limit) < 0)
64 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
65 limit.rlim_max = 5000000;
66 limit.rlim_cur = limit.rlim_max;
67 if (setrlimit (RLIMIT_STACK, &limit) < 0)
76 void *memory = malloc (5000000);
79 memset (memory, 17, 5000000);
83 ret = printf ("%.5000000f", 1.0);
84 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
86 ret = printf ("%.5000000f", -1.0);
87 return !(ret == 5000003 || (ret < 0 && errno == ENOMEM));
89 ret = printf ("%.5000000e", 1.0);
90 return !(ret >= 5000006 || (ret < 0 && errno == ENOMEM));
92 ret = printf ("%.5000000d", 1);
93 return !(ret == 5000000 || (ret < 0 && errno == ENOMEM));
95 ret = printf ("%.5000000d", -1);
96 return !(ret == 5000001 || (ret < 0 && errno == ENOMEM));
98 ret = printf ("%.5000000u", 1);
99 return !(ret == 5000000 || (ret < 0 && errno == ENOMEM));
107 main (int argc, char *argv[])