about summary refs log tree commit diff
path: root/time
diff options
context:
space:
mode:
Diffstat (limited to 'time')
-rw-r--r--time/tzfile.c23
-rw-r--r--time/tzset.c9
2 files changed, 28 insertions, 4 deletions
diff --git a/time/tzfile.c b/time/tzfile.c
index 2c178253e4..b118e07dc4 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -24,11 +24,14 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/stat.h>
 
 #define	NOID
 #include <timezone/tzfile.h>
 
 int __use_tzfile;
+static dev_t tzfile_dev;
+static ino64_t tzfile_ino;
 
 struct ttinfo
   {
@@ -97,6 +100,7 @@ __tzfile_read (const char *file, size_t extra, char **extrap)
   size_t total_size;
   size_t types_idx;
   size_t leaps_idx;
+  int was_using_tzfile = __use_tzfile;
 
   __use_tzfile = 0;
 
@@ -154,6 +158,25 @@ __tzfile_read (const char *file, size_t extra, char **extrap)
   if (f == NULL)
     return;
 
+  /* Get information about the file.  */
+  struct stat64 st;
+  if (fstat64 (fileno (f), &st) != 0)
+    {
+      fclose (f);
+      return;
+    }
+  if (was_using_tzfile && tzfile_ino == st.st_ino && tzfile_dev == st.st_dev)
+    {
+      /* It's the same file.  No further work needed.  */
+      fclose (f);
+      __use_tzfile = 1;
+      return;
+    }
+
+  /* Remember the inode and device number.  */
+  tzfile_dev = st.st_dev;
+  tzfile_ino = st.st_ino;
+
   /* No threads reading this stream.  */
   __fsetlocking (f, FSETLOCKING_BYCALLER);
 
diff --git a/time/tzset.c b/time/tzset.c
index 2274a38f59..aa866918e5 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -159,10 +159,7 @@ tzset_internal (always)
 
   /* Examine the TZ environment variable.  */
   tz = getenv ("TZ");
-  if (tz == NULL)
-    /* No user specification; use the site-wide default.  */
-    tz = TZDEFAULT;
-  else if (*tz == '\0')
+  if (tz && *tz == '\0')
     /* User specified the empty string; use UTC explicitly.  */
     tz = "Universal";
 
@@ -177,6 +174,10 @@ tzset_internal (always)
     /* No change, simply return.  */
     return;
 
+  if (tz == NULL)
+    /* No user specification; use the site-wide default.  */
+    tz = TZDEFAULT;
+
   tz_rules[0].name = NULL;
   tz_rules[1].name = NULL;