From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23695 invoked by alias); 2 Dec 2004 18:30:04 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 23675 invoked from network); 2 Dec 2004 18:30:04 -0000 Received: from unknown (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org with SMTP; 2 Dec 2004 18:30:04 -0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id iB2IThKi005916; Thu, 2 Dec 2004 19:29:43 +0100 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id iB2ITgBp005915; Thu, 2 Dec 2004 19:29:42 +0100 Date: Thu, 02 Dec 2004 18:30:00 -0000 From: Jakub Jelinek To: Ulrich Drepper , Roland McGrath , Paul Eggert Cc: Glibc hackers Subject: [PATCH] Fix mktime Message-ID: <20041202182942.GA5149@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-SW-Source: 2004-12/txt/msg00015.txt.bz2 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 * 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 +#include +#include + +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