]> code.delx.au - gnu-emacs/blobdiff - lib/time_rz.c
* test/lisp/help-fns-tests.el: Add several tests for 'describe-function'.
[gnu-emacs] / lib / time_rz.c
index cbbe2c6ac2faa123d5486e74228bd713e7e02dda..55b764ea8b3b63a66a62f1b86a3143b1dc7af774 100644 (file)
@@ -1,6 +1,6 @@
 /* Time zone functions such as tzalloc and localtime_rz
 
-   Copyright 2015 Free Software Foundation, Inc.
+   Copyright 2015-2016 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -47,8 +47,6 @@ enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
    used.  */
 enum { ABBR_SIZE_MIN = DEFAULT_MXFAST - offsetof (struct tm_zone, abbrs) };
 
-static char const TZ[] = "TZ";
-
 /* Magic cookie timezone_t value, for local time.  It differs from
    NULL and from all other timezone_t values.  Only the address
    matters; the pointer is never dereferenced.  */
@@ -90,8 +88,7 @@ extend_abbrs (char *abbrs, char const *abbr, size_t abbr_size)
 }
 
 /* Return a newly allocated time zone for NAME, or NULL on failure.
-   As a special case, return a nonzero constant for wall clock time, a
-   constant that survives freeing.  */
+   A null NAME stands for wall clock time (which is like unset TZ).  */
 timezone_t
 tzalloc (char const *name)
 {
@@ -105,7 +102,9 @@ tzalloc (char const *name)
       tz->tzname_copy[0] = tz->tzname_copy[1] = NULL;
 #endif
       tz->tz_is_set = !!name;
-      extend_abbrs (tz->abbrs, name, name_size);
+      tz->abbrs[0] = '\0';
+      if (name)
+        extend_abbrs (tz->abbrs, name, name_size);
     }
   return tz;
 }
@@ -204,7 +203,7 @@ tzfree (timezone_t tz)
 static char *
 getenv_TZ (void)
 {
-  return getenv (TZ);
+  return getenv ("TZ");
 }
 #endif
 
@@ -212,7 +211,7 @@ getenv_TZ (void)
 static int
 setenv_TZ (char const *tz)
 {
-  return tz ? setenv (TZ, tz, 1) : unsetenv (TZ);
+  return tz ? setenv ("TZ", tz, 1) : unsetenv ("TZ");
 }
 #endif
 
@@ -286,10 +285,8 @@ localtime_rz (timezone_t tz, time_t const *t, struct tm *tm)
       timezone_t old_tz = set_tz (tz);
       if (old_tz)
         {
-          tm = localtime_r (t, tm);
-          if (tm && !save_abbr (tz, tm))
-            tm = NULL;
-          if (revert_tz (old_tz))
+          bool abbr_saved = localtime_r (t, tm) && save_abbr (tz, tm);
+          if (revert_tz (old_tz) && abbr_saved)
             return tm;
         }
       return NULL;