523
517
libc_hidden_def (mktime)
524
518
libc_hidden_weak (timelocal)
530
not_equal_tm (const struct tm *a, const struct tm *b)
532
return ((a->tm_sec ^ b->tm_sec)
533
| (a->tm_min ^ b->tm_min)
534
| (a->tm_hour ^ b->tm_hour)
535
| (a->tm_mday ^ b->tm_mday)
536
| (a->tm_mon ^ b->tm_mon)
537
| (a->tm_year ^ b->tm_year)
538
| (a->tm_yday ^ b->tm_yday)
539
| (a->tm_isdst ^ b->tm_isdst));
543
print_tm (const struct tm *tp)
546
printf ("%04d-%02d-%02d %02d:%02d:%02d yday %03d wday %d isdst %d",
547
tp->tm_year + TM_YEAR_BASE, tp->tm_mon + 1, tp->tm_mday,
548
tp->tm_hour, tp->tm_min, tp->tm_sec,
549
tp->tm_yday, tp->tm_wday, tp->tm_isdst);
555
check_result (time_t tk, struct tm tmk, time_t tl, const struct tm *lt)
557
if (tk != tl || !lt || not_equal_tm (&tmk, lt))
561
printf (")\nyields (");
563
printf (") == %ld, should be %ld\n", (long int) tk, (long int) tl);
571
main (int argc, char **argv)
574
struct tm tm, tmk, tml;
579
if ((argc == 3 || argc == 4)
580
&& (sscanf (argv[1], "%d-%d-%d%c",
581
&tm.tm_year, &tm.tm_mon, &tm.tm_mday, &trailer)
583
&& (sscanf (argv[2], "%d:%d:%d%c",
584
&tm.tm_hour, &tm.tm_min, &tm.tm_sec, &trailer)
587
tm.tm_year -= TM_YEAR_BASE;
589
tm.tm_isdst = argc == 3 ? -1 : atoi (argv[3]);
592
lt = localtime (&tl);
598
printf ("mktime returns %ld == ", (long int) tl);
601
status = check_result (tl, tmk, tl, lt);
603
else if (argc == 4 || (argc == 5 && strcmp (argv[4], "-") == 0))
605
time_t from = atol (argv[1]);
606
time_t by = atol (argv[2]);
607
time_t to = atol (argv[3]);
610
for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
612
lt = localtime (&tl);
617
status |= check_result (tk, tmk, tl, &tml);
621
printf ("localtime (%ld) yields 0\n", (long int) tl);
625
if ((tl1 < tl) != (by < 0))
629
for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
631
/* Null benchmark. */
632
lt = localtime (&tl);
637
status |= check_result (tk, tmk, tl, &tml);
641
printf ("localtime (%ld) yields 0\n", (long int) tl);
645
if ((tl1 < tl) != (by < 0))
651
\t%s YYYY-MM-DD HH:MM:SS [ISDST] # Test given time.\n\
652
\t%s FROM BY TO # Test values FROM, FROM+BY, ..., TO.\n\
653
\t%s FROM BY TO - # Do not test those values (for benchmark).\n",
654
argv[0], argv[0], argv[0]);
663
compile-command: "gcc -DDEBUG -Wall -W -O -g mktime.c -o mktime"