This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

tzset is broken on 2.0.7



Looking at the mess in the time/ directory, I notice that tzset function
is kind of broken.

As per single unix spec:
     The tzset() function uses the value of the environment variable TZ to
     set time conversion information used by localtime(), ctime(),
     strftime() and mktime(). If TZ is absent from the environment,
     implementation- dependent default time zone information is used.

     The tzset() function sets the external variable tzname as follows:
	tzname[0] = "std";
	tzname[1] = "dst";

     where std and dst are as described in the XBD specification,
     Environment Variables.

     The tzset() function also sets the external variable daylight to 0 if
     Daylight Savings Time conversions should never be applied for the time
     zone in use; otherwise non-zero. The external variable timezone is set
     to the difference, in seconds, between Coordinated Universal Time (UTC)
     and local standard time.

Well, the attached test program proves that tzset() does nothing of the
above. (test case provided by EST Inc)

Again, looking at the time/tzset.c it would seem logical that the
tzset_internal() function should call tz_compute() at some time to have
the those extern variables set up to the right value, but now tzset just
happily reads the timezone file in (pointed by /etc/localtime), and if the
read was successfull ... it returns, doing nothing with the data.

However, the code is kind of twisted there and maybe someone else will
have a better idea for a fix. Glibc 2.1 is also affected by this bug.

Cristian
--
----------------------------------------------------------------------
Cristian Gafton   --   gafton@redhat.com   --   Red Hat Software, Inc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 UNIX is user friendly. It's just selective about who its friends are.
/* 
** The premise:  
**    If tzset and localtime
**    are working properly, they should
**    both return the same values.
*/
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char ** argv) {
  struct timeval tv;
  struct timezone tz;
  time_t t = time(NULL);

  /*
  ** Check to see the results of the archaic 
  ** gettimeofday function - we do this just because.
  */
  gettimeofday(&tv, &tz);
  printf("%ld\n", timezone);

  /*
  ** IF tzset WAS really working, timezone would 
  ** be properly configured and return a valid
  ** offset
  */
  tzset();
  printf("%ld\n", timezone);
  /*
  ** However, since tzset is BUSTED, it returns
  ** bumpkis.
  */
  /*
  ** But, if we call localtime() ...
  */
  localtime(&t);
  printf("%ld\n", timezone);

  /*
  ** The results - don't use tzset under libc 6 
  ** until this BUG is fixed.
  */

  exit(0);

}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]