9 equal_tm (struct tm
const *t
, struct tm
const *u
)
11 return (t
->tm_sec
== u
->tm_sec
&& t
->tm_min
== u
->tm_min
12 && t
->tm_hour
== u
->tm_hour
&& t
->tm_mday
== u
->tm_mday
13 && t
->tm_mon
== u
->tm_mon
&& t
->tm_year
== u
->tm_year
14 && t
->tm_wday
== u
->tm_wday
&& t
->tm_yday
== u
->tm_yday
15 && t
->tm_isdst
== u
->tm_isdst
&& t
->tm_gmtoff
== u
->tm_gmtoff
16 && t
->tm_zone
== u
->tm_zone
);
22 /* Calculate minimum time_t value. This would be simpler with C11,
23 which has _Generic, but we cannot assume C11. It would also
24 be simpler with intprops.h, which has TYPE_MINIMUM, but it's
25 better not to use glibc internals. */
26 time_t time_t_min
= -1;
27 time_t_min
= (0 < time_t_min
? 0
28 : sizeof time_t_min
== sizeof (long int) ? LONG_MIN
29 : sizeof time_t_min
== sizeof (long long int) ? LLONG_MIN
33 printf ("unknown time type\n");
36 time_t ymin
= time_t_min
/ 60 / 60 / 24 / 366;
37 bool mktime_should_fail
= ymin
== 0 || INT_MIN
+ 1900 < ymin
+ 1970;
39 struct tm tm0
= { .tm_year
= INT_MIN
, .tm_mday
= 1, .tm_wday
= -1 };
42 time_t t
= mktime (&tm
);
43 long long int llt
= t
;
44 bool mktime_failed
= tm
.tm_wday
== tm0
.tm_wday
;
48 if (! mktime_should_fail
)
50 printf ("mktime failed but should have succeeded\n");
55 printf ("mktime failed without setting errno");
60 printf ("mktime returned %lld but did not set tm_wday\n", llt
);
63 if (! equal_tm (&tm
, &tm0
))
65 printf ("mktime (P) failed but modified *P\n");
71 if (mktime_should_fail
)
73 printf ("mktime succeeded but should have failed\n");
76 struct tm
*lt
= localtime (&t
);
79 printf ("mktime returned a value rejected by localtime\n");
82 if (! equal_tm (lt
, &tm
))
84 printf ("mktime result does not match localtime result\n");
92 #include "support/test-driver.c"