This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi! The latest changes in mktime apparently broke mktime when tm_sec is < 0 or >= 60. mktime returns as if the tm_sec given was 0 resp. 59. 2004-12-01 Jakub Jelinek <jakub@redhat.com> * time/mktime.c (__mktime_internal): If sec_requested != sec, convert t2, not t. * time/Makefile (tests): Add tst-mktime3. * time/tst-mktime3.c: New test. --- libc/time/Makefile.jj 2004-11-01 13:25:55.000000000 +0100 +++ libc/time/Makefile 2004-12-02 19:03:43.945786121 +0100 @@ -34,7 +34,8 @@ aux := era alt_digit lc-time-cleanup distribute := datemsk tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ - tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime + tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \ + tst-mktime3 include ../Rules --- libc/time/mktime.c.jj 2004-11-12 13:58:25.000000000 +0100 +++ libc/time/mktime.c 2004-12-02 19:24:16.362448335 +0100 @@ -463,8 +463,9 @@ __mktime_internal (struct tm *tp, t2 = t1 + sec_adjustment; if (((t1 < t) != (sec_requested < 0)) | ((t2 < t1) != (sec_adjustment < 0)) - | ! (*convert) (&t, &tm)) + | ! (*convert) (&t2, &tm)) return -1; + t = t2; } *tp = tm; --- libc/time/tst-mktime3.c.jj 2004-12-02 19:00:40.590492064 +0100 +++ libc/time/tst-mktime3.c 2004-12-02 19:15:16.564452958 +0100 @@ -0,0 +1,48 @@ +#include <stdlib.h> +#include <stdio.h> +#include <time.h> + +struct tm tests[] = +{ + { .tm_sec = -1, .tm_mday = 1, .tm_year = 104 }, + { .tm_sec = 65, .tm_min = 59, .tm_hour = 23, .tm_mday = 31, + .tm_mon = 11, .tm_year = 101 } +}; +struct tm expected[] = +{ + { .tm_sec = 59, .tm_min = 59, .tm_hour = 23, .tm_mday = 31, + .tm_mon = 11, .tm_year = 103, .tm_wday = 3, .tm_yday = 364 }, + { .tm_sec = 5, .tm_mday = 1, .tm_year = 102, .tm_wday = 2 } +}; + +int +main (void) +{ + setenv ("TZ", "UTC", 1); + int i; + for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i) + { + if (mktime (&tests[i]) < 0) + { + printf ("mktime %d failed\n", i); + return 1; + } +#define CHECK(name) \ + if (tests[i].name != expected[i].name) \ + { \ + printf ("test %d " #name " got %d expected %d\n", \ + i, tests[i].name, expected[i].name); \ + return 1; \ + } + CHECK (tm_sec) + CHECK (tm_min) + CHECK (tm_hour) + CHECK (tm_mday) + CHECK (tm_mon) + CHECK (tm_year) + CHECK (tm_wday) + CHECK (tm_yday) + CHECK (tm_isdst) + } + return 0; +} Jakub
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |