From owner-freebsd-bugs Tue Sep 4 14:10:21 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id EBE6237B408 for ; Tue, 4 Sep 2001 14:10:01 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f84LA1k57815; Tue, 4 Sep 2001 14:10:01 -0700 (PDT) (envelope-from gnats) Received: from mailman.packetdesign.com (dns.packetdesign.com [65.192.41.10]) by hub.freebsd.org (Postfix) with ESMTP id 6757137B40C for ; Tue, 4 Sep 2001 14:01:05 -0700 (PDT) Received: from bubba.packetdesign.com (bubba.packetdesign.com [192.168.0.223]) by mailman.packetdesign.com (8.11.0/8.11.0) with ESMTP id f84L12222300 for ; Tue, 4 Sep 2001 14:01:02 -0700 (PDT) (envelope-from archie@packetdesign.com) Received: (from archie@localhost) by bubba.packetdesign.com (8.11.3/8.11.1) id f84L12873812; Tue, 4 Sep 2001 14:01:02 -0700 (PDT) (envelope-from archie) Message-Id: <200109042101.f84L12873812@bubba.packetdesign.com> Date: Tue, 4 Sep 2001 14:01:02 -0700 (PDT) From: Archie Cobbs Reply-To: archie@packetdesign.com To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: bin/30321: strftime(3) '%s' format does not work properly Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 30321 >Category: bin >Synopsis: strftime(3) '%s' format does not work properly >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Sep 04 14:10:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Archie Cobbs >Release: FreeBSD 4.3-RELEASE i386 >Organization: Packet Design >Environment: System: FreeBSD bubba.packetdesign.com 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Thu Apr 26 15:28:39 PDT 2001 root@bubba.packetdesign.com:/usr/obj/usr/src/sys/BUBBA i386 >Description: The strftime(3) '%s' format is supposed to convert a 'struct tm' into the number of seconds since the epoch (1/1/70 GMT). When it does this conversion, it uses the currently set system time zone instead of using the time zone from the 'struct tm' argument. Therefore, if the two timezones are different, incorrect results are computed. >How-To-Repeat: Run this program with your system time zone set to any timezone other than GMT. Notice that the value printed for "now" is different before and after the converstion. #include #include #include #include #include #include int main(int ac, char **av) { time_t now; char buf[32]; now = time(NULL); printf("now = %lu\n", (u_long)now); strftime(buf, sizeof(buf), "%s", gmtime(&now)); printf("now = %s\n", buf); return (0); } >Fix: I think this should fix it. From the timegm(3) man page, "The tm_isdst and tm_gmtoff members are forced to zero by timegm()" which I guess means that the value of 'tm_gmtoff' is added into the computation before being forced to zero. Index: strftime.c =================================================================== RCS file: /home/cvs/freebsd/src/lib/libc/stdtime/strftime.c,v retrieving revision 1.25.2.3 diff -u -r1.25.2.3 strftime.c --- strftime.c 2001/02/18 04:06:49 1.25.2.3 +++ strftime.c 2001/09/04 20:58:27 @@ -244,7 +244,7 @@ time_t mkt; tm = *t; - mkt = mktime(&tm); + mkt = timegm(&tm); if (TYPE_SIGNED(time_t)) (void) sprintf(buf, "%ld", (long) mkt); >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message