Subject: lib/577: mktime does not call tzset()
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: Brian D. Carlstrom <bdc@JOLT.MIT.EDU>
List: netbsd-bugs
Date: 11/16/1994 16:35:03
>Number:         577
>Category:       lib
>Synopsis:       mktime does not call tzset
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Nov 16 16:35:02 1994
>Originator:     Brian D. Carlstrom
>Organization:
"MIT AI Lab	"
>Release:        1.0
>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...

>Audit-Trail:
>Unformatted: