Refactor to help the compiler.
* time/tzfile.c (__tzfile_read): Assume the arg is a nonempty string.
Caller changed.
* time/tzset.c (tzset_internal): Simplify due to the fact that
TZDEFAULT is not a null pointer (tzfile.c is already assuming this).
Do not pass an empty string to __tzfile_read.
---
time/tzfile.c | 33 ++++++++++++---------------------
time/tzset.c | 24 ++++++++++++++----------
2 files changed, 26 insertions(+), 31 deletions(-)
@@ -156,28 +156,19 @@ __tzfile_read (const char *file)
__use_tzfile = false;
- if (file == NULL)
- /* No user specification; use the site-wide default. */
- file = TZDEFAULT;
- else if (*file == '\0')
- /* User specified the empty string; use UTC with no leap seconds. */
+ /* We must not allow to read an arbitrary file in a setuid
+ program. So we fail for any file which is not in the
+ directory hierarchy starting at TZDIR
+ and which is not the system wide default TZDEFAULT. */
+ if (__libc_enable_secure
+ && ((*file == '/'
+ && strcmp (file, TZDEFAULT) != 0
+ && (strncmp (file, default_tzdir, sizeof (default_tzdir) - 1)
+ != 0))
+ || strstr (file, "../") != NULL))
+ /* This test is certainly a bit too restrictive but it should
+ catch all critical cases. */
goto ret_free_transitions;
- else
- {
- /* We must not allow to read an arbitrary file in a setuid
- program. So we fail for any file which is not in the
- directory hierarchy starting at TZDIR
- and which is not the system wide default TZDEFAULT. */
- if (__libc_enable_secure
- && ((*file == '/'
- && strcmp (file, TZDEFAULT) != 0
- && (strncmp (file, default_tzdir, sizeof (default_tzdir) - 1)
- != 0))
- || strstr (file, "../") != NULL))
- /* This test is certainly a bit too restrictive but it should
- catch all critical cases. */
- goto ret_free_transitions;
- }
if (*file != '/')
{
@@ -394,25 +394,26 @@ tzset_internal (int always)
/* Examine the TZ environment variable. */
tz = getenv ("TZ");
- if (tz && *tz == '\0')
+
+ if (tz == NULL)
+ /* No user specification; use the site-wide default. */
+ tz = TZDEFAULT;
+
+ if (*tz == '\0')
/* User specified the empty string; use UTC explicitly. */
tz = "Universal";
/* A leading colon means "implementation defined syntax".
We ignore the colon and always use the same algorithm:
try a data file, and if none exists parse the 1003.1 syntax. */
- if (tz && *tz == ':')
+ if (*tz == ':')
++tz;
/* Check whether the value changed since the last run. */
- if (old_tz != NULL && tz != NULL && strcmp (tz, old_tz) == 0)
+ if (old_tz != NULL && strcmp (tz, old_tz) == 0)
/* 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;
@@ -421,9 +422,12 @@ tzset_internal (int always)
old_tz = __strdup (tz);
/* Try to read a data file. */
- __tzfile_read (tz);
- if (__use_tzfile)
- return;
+ if (*tz != '\0')
+ {
+ __tzfile_read (tz);
+ if (__use_tzfile)
+ return;
+ }
/* No data file found. Default to UTC if nothing specified or if
TZDEFAULT is broken. */