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]

Re: tzset is broken on 2.0.7



Hi,

there're even more errors in the time code:
- timezone shouldn't include the daylight saving time offset, but it does
- neither timezone (as reported by Cristian) nor daylight are set
- daylight is set to tm_isdst which is wrong: daylight should be 0 if
  daylight saving time is _never_ used

I'm appending a first version of a small test program.  I'll try to
enhance the program with some more tests for inclusion in glibc.

Andreas

#define _GNU_SOURCE 1
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int failed = 0;

struct test_times 
{
  const char *name;
  int        daylight;
  int        timezone;
};

static const struct test_times tests [] =
{
  { "Europe/Berlin", 1, -3600},
  { "Universal", 0, 0},
  { "Australia/Melbourne", 1, -36000},
  { "America/Sao_Paulo", 1, 10800},
  { NULL, 0, 0}
};


void
print_tzvars (void)
{
  printf ("tzname[0]: %s\n", tzname[0]);
  printf ("tzname[1]: %s\n", tzname[1]);
  printf ("daylight: %d\n", daylight);
  printf ("timezone: %d\n", timezone);
}


void
check_tzvars (const char *name, int dayl, int timez)
{
  if (daylight != dayl)
    {
      printf ("Timezone: %s, daylight is: %d but should be: %d\n",
	      name, daylight, dayl);
      ++failed;
    }
  if (timezone != timez)
    {
      printf ("Timezone: %s, timezone is: %d but should be: %d\n",
	      name, timezone, timez);
      ++failed;
    }
}


int
main (int argc, char ** argv)
{
  time_t t = time(NULL);
  const struct test_times *pt;
  char buf[BUFSIZ];

  for (pt = tests; pt->name != NULL; ++pt)
    {
      /* Start with a known state */
      printf ("Checking timezone %s\n", pt->name);
      sprintf(buf, "TZ=%s", pt->name);
      if (putenv (buf))
	{
	  puts ("putenv failed.");
	  failed = 1;
	}
      tzset ();
      print_tzvars ();
      check_tzvars (pt->name, pt->daylight, pt->timezone);

      /* calling localtime shouldn't make a difference */
      localtime(&t);
      print_tzvars ();
      check_tzvars (pt->name, pt->daylight, pt->timezone);
    }

  return (failed ? EXIT_FAILURE : EXIT_SUCCESS);
}

-- 
 Andreas Jaeger   aj@arthur.rhein-neckar.de    jaeger@informatik.uni-kl.de
  for pgp-key finger ajaeger@alma.student.uni-kl.de


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