annotate tests/test-printf-posix2.c @ 14079:97fc9a21a8fb

maint: update almost all copyright ranges to include 2011 Run the new "make update-copyright" rule.
author Jim Meyering <meyering@redhat.com>
date Sat, 01 Jan 2011 20:17:23 +0100
parents c2cbabec01dd
children 8250f2777afc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of POSIX compatible printf() function.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 12559
diff changeset
2 Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stdio.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #if HAVE_GETRLIMIT && HAVE_SETRLIMIT
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdlib.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <sys/types.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <sys/time.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <sys/resource.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <string.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include <errno.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 int
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 main (int argc, char *argv[])
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 {
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 struct rlimit limit;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 int arg;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 int ret;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 /* Some printf implementations allocate temporary space with malloc. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 #ifdef RLIMIT_DATA
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 if (getrlimit (RLIMIT_DATA, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 limit.rlim_max = 5000000;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 limit.rlim_cur = limit.rlim_max;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 if (setrlimit (RLIMIT_DATA, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 #endif
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 #ifdef RLIMIT_AS
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 if (getrlimit (RLIMIT_AS, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 limit.rlim_max = 5000000;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 limit.rlim_cur = limit.rlim_max;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 if (setrlimit (RLIMIT_AS, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 #endif
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 /* Some printf implementations allocate temporary space on the stack. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 #ifdef RLIMIT_STACK
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 if (getrlimit (RLIMIT_STACK, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 limit.rlim_max = 5000000;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 limit.rlim_cur = limit.rlim_max;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 if (setrlimit (RLIMIT_STACK, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 #endif
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 arg = atoi (argv[1]);
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 switch (arg)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 {
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 case 0:
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9443
diff changeset
76 void *memory = malloc (5000000);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9443
diff changeset
77 if (memory == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9443
diff changeset
78 return 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9443
diff changeset
79 memset (memory, 17, 5000000);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9443
diff changeset
80 return 78;
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 }
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 case 1:
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 ret = printf ("%.5000000f", 1.0);
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 case 2:
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 ret = printf ("%.5000000f", -1.0);
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 return !(ret == 5000003 || (ret < 0 && errno == ENOMEM));
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 case 3:
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 ret = printf ("%.5000000e", 1.0);
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 return !(ret >= 5000006 || (ret < 0 && errno == ENOMEM));
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 case 4:
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 ret = printf ("%.5000000d", 1);
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 return !(ret == 5000000 || (ret < 0 && errno == ENOMEM));
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 case 5:
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 ret = printf ("%.5000000d", -1);
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 return !(ret == 5000001 || (ret < 0 && errno == ENOMEM));
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 case 6:
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 ret = printf ("%.5000000u", 1);
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 return !(ret == 5000000 || (ret < 0 && errno == ENOMEM));
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 }
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 return 0;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 }
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 #else
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 int
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 main (int argc, char *argv[])
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 {
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 }
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 #endif