source: branches/libc-0.6/testcase/mktime.c@ 2492

Last change on this file since 2492 was 1509, checked in by bird, 21 years ago

todo

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1/* confdefs.h. */
2
3#define PACKAGE_NAME "GNU coreutils"
4#define PACKAGE_TARNAME "coreutils"
5#define PACKAGE_VERSION "5.2.1"
6#define PACKAGE_STRING "GNU coreutils 5.2.1"
7#define PACKAGE_BUGREPORT "bug-coreutils@gnu.org"
8#define PACKAGE "coreutils"
9#define VERSION "5.2.1"
10#define _GNU_SOURCE 1
11#define STDC_HEADERS 1
12#define HAVE_SYS_TYPES_H 1
13#define HAVE_SYS_STAT_H 1
14#define HAVE_STDLIB_H 1
15#define HAVE_STRING_H 1
16#define HAVE_MEMORY_H 1
17#define HAVE_STRINGS_H 1
18#define HAVE_INTTYPES_H 1
19#define HAVE_STDINT_H 1
20#define HAVE_UNISTD_H 1
21#define __EXTENSIONS__ 1
22#define HAVE_UNAME 1
23#define PROTOTYPES 1
24#define STDC_HEADERS 1
25#define HAVE_STRING_H 1
26#define HAVE_LONG_DOUBLE 1
27#define HAVE_ERRNO_H 1
28#define HAVE_FCNTL_H 1
29#define HAVE_FLOAT_H 1
30#define HAVE_LIMITS_H 1
31#define HAVE_MEMORY_H 1
32#define HAVE_NETDB_H 1
33#define HAVE_STDLIB_H 1
34#define HAVE_STDDEF_H 1
35#define HAVE_STDINT_H 1
36#define HAVE_STRING_H 1
37#define HAVE_SYS_IOCTL_H 1
38#define HAVE_SYS_PARAM_H 1
39#define HAVE_SYS_RESOURCE_H 1
40#define HAVE_SYS_SOCKET_H 1
41#define HAVE_SYS_STATFS_H 1
42#define HAVE_SYS_TIME_H 1
43#define HAVE_SYS_TIMEB_H 1
44#define HAVE_SYS_WAIT_H 1
45#define HAVE_SYSLOG_H 1
46#define HAVE_TERMIOS_H 1
47#define HAVE_UNISTD_H 1
48#define HAVE_UTIME_H 1
49#define HAVE_DIRENT_H 1
50#define HAVE_STRUCT_STAT_ST_BLOCKS 1
51#define HAVE_ST_BLOCKS 1
52#define GETGROUPS_T gid_t
53#define RETSIGTYPE void
54#define HAVE_INTTYPES_H_WITH_UINTMAX 1
55#define HAVE_STDINT_H_WITH_UINTMAX 1
56#define HAVE_UNSIGNED_LONG_LONG 1
57#define HAVE_UINTMAX_T 1
58#define HOST_OPERATING_SYSTEM "OS/2"
59#define HAVE_SYS_TIME_H 1
60#define HAVE_UTIME_H 1
61#define TIME_WITH_SYS_TIME 1
62#define HAVE_STRUCT_UTIMBUF 1
63#define HAVE_STRUCT_DIRENT_D_TYPE 1
64#define D_INO_IN_DIRENT 1
65#define HAVE_GRP_H 1
66#define HAVE_MEMORY_H 1
67#define HAVE_PWD_H 1
68#define HAVE_STRING_H 1
69#define HAVE_STRINGS_H 1
70#define HAVE_STDLIB_H 1
71#define HAVE_UNISTD_H 1
72#define HAVE_SYS_TIME_H 1
73#define HAVE_DECL_FREE 1
74#define HAVE_DECL_GETENV 1
75#define HAVE_DECL_GETEUID 1
76#define HAVE_DECL_GETGRGID 1
77#define HAVE_DECL_GETLOGIN 1
78#define HAVE_DECL_GETPWUID 1
79#define HAVE_DECL_GETUID 1
80#define HAVE_DECL_GETUTENT 0
81#define HAVE_DECL_LSEEK 1
82#define HAVE_DECL_MALLOC 1
83#define HAVE_DECL_MEMCHR 1
84#define HAVE_DECL_MEMRCHR 0
85#define HAVE_DECL_NANOSLEEP 1
86#define HAVE_DECL_REALLOC 1
87#define HAVE_DECL_STPCPY 1
88#define HAVE_DECL_STRNDUP 1
89#define HAVE_DECL_STRNLEN 1
90#define HAVE_DECL_STRSTR 1
91#define HAVE_DECL_STRTOUL 1
92#define HAVE_DECL_STRTOULL 1
93#define HAVE_DECL_TTYNAME 1
94#define getline gnu_getline
95#define HAVE__BOOL 1
96#define HAVE_STDBOOL_H 1
97#define HAVE_FCNTL_H 1
98#define HAVE_UNISTD_H 1
99#define HAVE_DECL_GETENV 1
100#define HAVE_MKSTEMP 1
101#define mkstemp rpl_mkstemp
102#define HAVE_STDINT_H 1
103#define HAVE_GETTIMEOFDAY 1
104#define FILESYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX 0
105#define FILESYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR 0
106#define HAVE_LONG_FILE_NAMES 1
107#define D_INO_IN_DIRENT 1
108#define HAVE_PATHCONF 1
109#define HAVE_NETDB_H 1
110#define HAVE_SYS_SOCKET_H 1
111#define HAVE_NETINET_IN_H 1
112#define HAVE_ARPA_INET_H 1
113#define HAVE_DECL_STRERROR_R 1
114#define HAVE_STRERROR_R 1
115#define HAVE_ISASCII 1
116#define HAVE_SYS_PARAM_H 1
117#define HAVE_STRUCT_STAT_ST_BLOCKS 1
118#define HAVE_ST_BLOCKS 1
119#define HAVE_ALLOCA_H 1
120#define HAVE_ALLOCA 1
121#define HAVE_ATEXIT 1
122#define HAVE_DUP2 1
123#define HAVE_GETGROUPS 1
124#define HAVE_DECL_EUIDACCESS 0
125#define mbstate_t int
126#define HAVE_DECL_GETENV 1
127#define HAVE_MEMPCPY 1
128#define fnmatch gnu_fnmatch
129#define HAVE_UNAME 1
130#define C_GETLOADAVG 1
131#define HAVE_SETLOCALE 1
132#define HAVE_GETPASS 1
133#define HAVE_MEMCHR 1
134#define HAVE_MEMCPY 1
135#define HAVE_MEMMOVE 1
136#define HAVE_MEMSET 1
137#define HAVE_STDLIB_H 1
138#define HAVE_SYS_TIME_H 1
139#define HAVE_UNISTD_H 1
140/* end confdefs.h. */
141/* Test program from Paul Eggert and Tony Leneis. */
142#if TIME_WITH_SYS_TIME
143# include <sys/time.h>
144# include <time.h>
145#else
146# if HAVE_SYS_TIME_H
147# include <sys/time.h>
148# else
149# include <time.h>
150# endif
151#endif
152
153#if HAVE_STDLIB_H
154# include <stdlib.h>
155#endif
156
157#if HAVE_UNISTD_H
158# include <unistd.h>
159#endif
160
161#if !HAVE_ALARM
162# define alarm(X) /* empty */
163#endif
164
165/* Work around redefinition to rpl_putenv by other config tests. */
166#undef putenv
167
168static time_t time_t_max;
169static time_t time_t_min;
170
171/* Values we'll use to set the TZ environment variable. */
172static char *tz_strings[] = {
173 (char *) 0, "TZ=GMT0", "TZ=JST-9",
174 "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
175};
176#define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
177
178/* Fail if mktime fails to convert a date in the spring-forward gap.
179 Based on a problem report from Andreas Jaeger. */
180static void
181spring_forward_gap ()
182{
183 /* glibc (up to about 1998-10-07) failed this test. */
184 struct tm tm;
185
186 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
187 instead of "TZ=America/Vancouver" in order to detect the bug even
188 on systems that don't support the Olson extension, or don't have the
189 full zoneinfo tables installed. */
190 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
191
192 tm.tm_year = 98;
193 tm.tm_mon = 3;
194 tm.tm_mday = 5;
195 tm.tm_hour = 2;
196 tm.tm_min = 0;
197 tm.tm_sec = 0;
198 tm.tm_isdst = -1;
199 if (mktime (&tm) == (time_t)-1)
200 exit (1);
201}
202
203static void
204mktime_test1 (now)
205 time_t now;
206{
207 struct tm *lt;
208 if ((lt = localtime (&now)) && mktime (lt) != now)
209 exit (1);
210}
211
212static void
213mktime_test (now)
214 time_t now;
215{
216 mktime_test1 (now);
217 mktime_test1 ((time_t) (time_t_max - now));
218 mktime_test1 ((time_t) (time_t_min + now));
219}
220
221static void
222irix_6_4_bug ()
223{
224 /* Based on code from Ariel Faigon. */
225 struct tm tm;
226 tm.tm_year = 96;
227 tm.tm_mon = 3;
228 tm.tm_mday = 0;
229 tm.tm_hour = 0;
230 tm.tm_min = 0;
231 tm.tm_sec = 0;
232 tm.tm_isdst = -1;
233 mktime (&tm);
234 if (tm.tm_mon != 2 || tm.tm_mday != 31)
235 exit (1);
236}
237
238static void
239bigtime_test (j)
240 int j;
241{
242 struct tm tm;
243 time_t now;
244 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
245 now = mktime (&tm);
246 if (now != (time_t) -1)
247 {
248 struct tm *lt = localtime (&now);
249 if (! (lt
250 && lt->tm_year == tm.tm_year
251 && lt->tm_mon == tm.tm_mon
252 && lt->tm_mday == tm.tm_mday
253 && lt->tm_hour == tm.tm_hour
254 && lt->tm_min == tm.tm_min
255 && lt->tm_sec == tm.tm_sec
256 && lt->tm_yday == tm.tm_yday
257 && lt->tm_wday == tm.tm_wday
258 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
259 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
260 exit (1);
261 }
262}
263
264int
265main ()
266{
267 time_t t, delta;
268 int i, j;
269
270 /* This test makes some buggy mktime implementations loop.
271 Give up after 60 seconds; a mktime slower than that
272 isn't worth using anyway. */
273 alarm (60);
274
275 for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
276 continue;
277 time_t_max--;
278 if ((time_t) -1 < 0)
279 for (time_t_min = -1; (time_t) (time_t_min * 2) < 0; time_t_min *= 2)
280 continue;
281 delta = time_t_max / 997; /* a suitable prime number */
282 for (i = 0; i < N_STRINGS; i++)
283 {
284 if (tz_strings[i])
285 putenv (tz_strings[i]);
286
287 for (t = 0; t <= time_t_max - delta; t += delta)
288 mktime_test (t);
289 mktime_test ((time_t) 1);
290 mktime_test ((time_t) (60 * 60));
291 mktime_test ((time_t) (60 * 60 * 24));
292
293 for (j = 1; 0 < j; j *= 2)
294 bigtime_test (j);
295 bigtime_test (j - 1);
296 }
297 irix_6_4_bug ();
298 spring_forward_gap ();
299 exit (0);
300}
301
Note: See TracBrowser for help on using the repository browser.