Back to index

glibc  2.9
Functions | Variables
tst-posixtz.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

Go to the source code of this file.

Functions

int main (void)

Variables

struct {
time_t when
const char * tz
const char * result
tests []

Function Documentation

int main ( void  )

Definition at line 28 of file tst-posixtz.c.

{
  int result = 0;
  size_t cnt;

  for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
    {
      char buf[100];
      struct tm *tmp;

      printf ("TZ = \"%s\", time = %ld => ", tests[cnt].tz, tests[cnt].when);
      fflush (stdout);

      setenv ("TZ", tests[cnt].tz, 1);

      tmp = localtime (&tests[cnt].when);

      snprintf (buf, sizeof (buf),
              "%04d/%02d/%02d %02d:%02d:%02d dst=%d zone=%s",
              tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
              tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tmp->tm_isdst,
              tzname[tmp->tm_isdst ? 1 : 0]);

      fputs (buf, stdout);

      if (strcmp (buf, tests[cnt].result) == 0)
       puts (", OK");
      else
       {
         result = 1;
         puts (", FAIL");
       }
    }

  setenv ("TZ", "Universal", 1);
  localtime (&tests[0].when);
  printf ("TZ = \"Universal\" daylight %d tzname = { \"%s\", \"%s\" }",
         daylight, tzname[0], tzname[1]);
  if (! daylight)
    puts (", OK");
  else
    {
      result = 1;
      puts (", FAIL");
    }

  setenv ("TZ", "AEST-10AEDST-11,M10.5.0,M3.5.0", 1);
  tzset ();
  printf ("TZ = \"AEST-10AEDST-11,M10.5.0,M3.5.0\" daylight %d"
         " tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]);
  if (daylight
      && strcmp (tzname[0], "AEST") == 0 && strcmp (tzname[1], "AEDST") == 0)
    puts (", OK");
  else
    {
      result = 1;
      puts (", FAIL");
    }

  return result;
}

Here is the call graph for this function:


Variable Documentation

struct { ... } tests[]