NetBSD Problem Report #577

From gnats  Wed Nov 16 16:28:34 1994
Received: from pain.lcs.mit.edu (pain.lcs.mit.edu [128.52.46.239]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id QAA00929 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Wed, 16 Nov 1994 16:28:32 -0800
Message-Id: <199411170028.TAA03817@fnord.mit.edu>
Date: Wed, 16 Nov 1994 19:28:15 -0500
From: "Brian D. Carlstrom" <bdc@JOLT.MIT.EDU>
Reply-To: bdc@ai.mit.edu
To: gnats-bugs@NetBSD.ORG
Subject: mktime does not call tzset()
X-Send-Pr-Version: 3.2

>Number:         577
>Category:       lib
>Synopsis:       mktime does not call tzset
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Nov 16 16:35:02 +0000 1994
>Closed-Date:    Sun Nov 20 00:37:46 +0000 1994
>Last-Modified:  
>Originator:     Brian D. Carlstrom
>Release:        1.0
>Organization:
"MIT AI Lab	"
>Environment:

System: NetBSD fnord.mit.edu 1.0 NetBSD 1.0 (FNORD) #0: Fri Oct 21 15:03:57 EDT 1994 bdc@fnord.mit.edu:/usr/src/sys/arch/i386/compile/FNORD i386


>Description:

In NetBSD's time package, the mktime() function does not call tzset()
before doing time conversion. This is required by POSIX. See Section 8.1.1,
lines 113-114.
>How-To-Repeat:

/* Unless your current time zone is GMT, this program should print out
** two different numbers. If the numbers are the same, then mktime()
** is broken.
*/
#include <time.h>
#include <stdio.h>

extern char **environ;

main()
{
  time_t t, t1;
  struct tm d;

  time(&t);
  d = *localtime(&t);

  printf("%d time, offset %d %s\n", t, d.tm_gmtoff, d.tm_zone);

  /* Here, we reinterpret the time as GMT by temporarily setting $TZ to
  ** "TZ=UCT0" and passing the date to mktime().
  */
  { char *newenv[2],
    **oldenv = environ;
    newenv[0] = "TZ=UCT0"; newenv[1] = 0;
    environ=newenv;
#ifdef LOSE
    tzset();                    /* Remove this, and the program won't work. */
#endif
    t1 = mktime(&d);
    environ=oldenv;
  }

  printf("%d UCT0 time\n", t1);

}


>Fix:

i'm just reporting this for someone else. no solution from me.
i suppose mktime can just call tzset but there might be something
better to do in the library...

>Release-Note:
>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: jtc
State-Changed-When: Sun Nov 20 00:37:46 1994
State-Changed-Why:
Changed localsub() so that tzset() is called unconditionally.  This change 
causes ctime, localtime() and mktime() to conform to POSIX.1's requirement
that these functions behave as if they called tzset().


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.