about summary refs log tree commit diff
path: root/time
diff options
context:
space:
mode:
Diffstat (limited to 'time')
-rw-r--r--time/Makefile2
-rw-r--r--time/clocktest.c31
-rw-r--r--time/test-tz.c57
-rw-r--r--time/tzset.c10
4 files changed, 89 insertions, 11 deletions
diff --git a/time/Makefile b/time/Makefile
index bd4d6b1c3c..dd5014104a 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -33,7 +33,7 @@ routines	:= offtime asctime clock ctime difftime gmtime	\
 		   strptime
 
 others	:= ap zdump zic
-tests	:= test_time clocktest
+tests	:= test_time clocktest test-tz
 
 tzfiles := africa antarctica asia australasia europe northamerica \
 	   southamerica etcetera factory systemv backward
diff --git a/time/clocktest.c b/time/clocktest.c
index 0a248aa181..570c194a81 100644
--- a/time/clocktest.c
+++ b/time/clocktest.c
@@ -1,16 +1,31 @@
+#include <signal.h>
 #include <stdio.h>
 #include <time.h>
+#include <unistd.h>
 
-main ()
+volatile int gotit = 0;
+
+void
+alarm_handler (int signal)
+{
+    gotit = 1;
+}
+
+
+int
+main (int argc, char ** argv)
 {
-  volatile int i;
-  double t1, t2, t;
+  clock_t start, stop;
 
-  t1 = (double) clock ();
-  for (i = 0; i < 100000; ++i) ;
-  t2 = (double) clock ();
+  signal(SIGALRM, alarm_handler);
+  alarm(1);
+  start = clock ();
+  while (!gotit);
+  stop = clock ();
 
-  t = (t2 - t1) / ((double) CLOCKS_PER_SEC);
-  printf ("%f - %f = %f\n",t2,t1,t);
+  printf ("%ld clock ticks per second (start=%ld,stop=%ld)\n",
+	  stop - start, start, stop);
+  printf ("CLOCKS_PER_SEC=%d, sysconf(_SC_CLK_TCK)=%ld\n",
+	  CLOCKS_PER_SEC, sysconf(_SC_CLK_TCK));
   return 0;
 }
diff --git a/time/test-tz.c b/time/test-tz.c
new file mode 100644
index 0000000000..47565cedec
--- /dev/null
+++ b/time/test-tz.c
@@ -0,0 +1,57 @@
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <stdio.h>
+
+struct {
+  const char *	env;
+  time_t	expected;
+} tests[] = {
+  {"TZ=MST",		832935315},
+  {"TZ=",		832910115},
+  {"TZ=:UTC",		832910115},
+  {"TZ=UTC",		832910115},
+  {"TZ=UTC0",		832910115}
+};
+
+
+int
+main(int argc, char ** argv)
+{
+  int errors = 0;
+  struct tm tm;
+  time_t t;
+  int i;
+
+  memset (&tm, 0, sizeof (tm));
+  tm.tm_isdst = 0;
+  tm.tm_year  = 96;	/* years since 1900 */
+  tm.tm_mon   = 4;
+  tm.tm_mday  = 24;
+  tm.tm_hour  =  3;
+  tm.tm_min   = 55;
+  tm.tm_sec   = 15;
+
+  for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
+    {
+      putenv (tests[i].env);
+      tzset ();
+      t = mktime(&tm);
+      if (t != tests[i].expected)
+	{
+	  printf ("%s: flunked test %d (expected %lu, got %lu)\n",
+		  argv[0], i, (long) tests[i].expected, (long) t);
+	  ++errors;
+	}
+    }
+  if (errors == 0)
+    {
+      puts ("No errors.");
+      exit (EXIT_SUCCESS);
+    }
+  else
+    {
+      printf ("%d errors.\n", errors);
+      exit (EXIT_FAILURE);
+    }
+}
diff --git a/time/tzset.c b/time/tzset.c
index 007997f541..5f949dce5f 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -85,10 +85,16 @@ DEFUN_VOID(__tzset)
 
   /* Free old storage.  */
   if (tz_rules[0].name != NULL && *tz_rules[0].name != '\0')
-    free((PTR) tz_rules[0].name);
+    {
+      free((PTR) tz_rules[0].name);
+      tz_rules[0].name = NULL;
+    }
   if (tz_rules[1].name != NULL && *tz_rules[1].name != '\0' &&
       tz_rules[1].name != tz_rules[0].name)
-    free((PTR) tz_rules[1].name);
+    {
+      free((PTR) tz_rules[1].name);
+      tz_rules[1].name = NULL;
+    }
 
   /* Examine the TZ environment variable.  */
   tz = getenv ("TZ");