-/* Copyright (C) 1991, 92, 93, 95, 96, 97, 98 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,95,96,97,98,99 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <stdlib.h>
+#include <assert.h>
+#include <limits.h>
#include <stdio.h>
-#include <time.h>
+#include <stdlib.h>
#include <string.h>
-#include <limits.h>
+#include <time.h>
#include <unistd.h>
#define NOID
long int change; /* Seconds of correction to apply. */
};
-extern char * __tzstring (const char *); /* Defined in tzset.c. */
-
static struct ttinfo *find_transition (time_t timer) internal_function;
static void compute_tzname_max (size_t) internal_function;
if (num_transitions > 0)
{
- transitions = (time_t *) malloc (num_transitions * sizeof(time_t));
+ transitions = (time_t *) malloc (num_transitions * sizeof (time_t));
if (transitions == NULL)
goto lose;
type_idxs = (unsigned char *) malloc (num_transitions);
processed when sizeof (time_t) > 4. */
i = num_transitions;
while (i-- > 0)
- transitions[i] = decode ((char *) transitions + i*4);
+ transitions[i] = decode ((char *) transitions + i * 4);
}
for (i = 0; i < num_types; ++i)
|| fread_unlocked (&types[i].isdst, 1, 1, f) != 1
|| fread_unlocked (&types[i].idx, 1, 1, f) != 1)
goto lose;
+ if (types[i].isdst > 1)
+ goto lose;
if (types[i].idx >= chars) /* Bogus index in data file. */
goto lose;
types[i].offset = (long int) decode (x);
fclose (f);
+ /* First "register" all timezone names. */
+ for (i = 0; i < num_types; ++i)
+ (void) __tzstring (&zone_names[types[i].idx]);
+
/* Find the standard and daylight time offsets used by the rule file.
We choose the offsets in the types of each flavor that are
transitioned to earliest in time. */
+ __tzname[0] = NULL;
__tzname[1] = NULL;
- for (i = 0; i < num_types; ++i)
- __tzname[types[i].isdst] = __tzstring (&zone_names[types[i].idx]);
+ for (i = num_transitions; i > 0; )
+ {
+ int type = type_idxs[--i];
+ int dst = types[type].isdst;
+
+ if (__tzname[dst] == NULL)
+ {
+ int idx = types[type].idx;
+
+ __tzname[dst] = __tzstring (&zone_names[idx]);
+
+ if (__tzname[1 - dst] != NULL)
+ break;
+ }
+ }
+ if (__tzname[0] == NULL)
+ {
+ /* This should only happen if there are no transition rules.
+ In this case there should be only one single type. */
+ assert (num_types == 1);
+ __tzname[0] = __tzstring (zone_names);
+ }
if (__tzname[1] == NULL)
__tzname[1] = __tzname[0];
compute_tzname_max (chars);
if (num_transitions == 0)
- /* Use the first rule (which should also be the only one. */
+ /* Use the first rule (which should also be the only one). */
rule_stdoff = rule_dstoff = types[0].offset;
else
{
+ int stdoff_set = 0, dstoff_set = 0;
rule_stdoff = rule_dstoff = 0;
- for (i = 0; i < num_transitions; ++i)
+ i = num_transitions - 1;
+ do
{
- if (!rule_stdoff && !types[type_idxs[i]].isdst)
- rule_stdoff = types[type_idxs[i]].offset;
- if (!rule_dstoff && types[type_idxs[i]].isdst)
- rule_dstoff = types[type_idxs[i]].offset;
- if (rule_stdoff && rule_dstoff)
+ if (!stdoff_set && !types[type_idxs[i]].isdst)
+ {
+ stdoff_set = 1;
+ rule_stdoff = types[type_idxs[i]].offset;
+ }
+ else if (!dstoff_set && types[type_idxs[i]].isdst)
+ {
+ dstoff_set = 1;
+ rule_dstoff = types[type_idxs[i]].offset;
+ }
+ if (stdoff_set && dstoff_set)
break;
}
+ while (i-- > 0);
+
+ if (!dstoff_set)
+ rule_dstoff = rule_stdoff;
}
__daylight = rule_stdoff != rule_dstoff;
}
__mempcpy (__mempcpy (zone_names, std, stdlen), dst, dstlen);
+ /* Now there are only two zones, regardless of what the file contained. */
+ num_types = 2;
+
/* Now correct the transition times for the user-specified standard and
daylight offsets from GMT. */
isdst = 0;
struct ttinfo *info = find_transition (timer);
__daylight = rule_stdoff != rule_dstoff;
__timezone = -rule_stdoff;
+ __tzname[0] = NULL;
__tzname[1] = NULL;
- for (i = 0; i < num_types; ++i)
- __tzname[types[i].isdst] = __tzstring (&zone_names[types[i].idx]);
+ for (i = num_transitions; i > 0; )
+ {
+ int type = type_idxs[--i];
+ int dst = types[type].isdst;
+ int idx = types[type].idx;
+
+ if (__tzname[dst] == NULL)
+ {
+ __tzname[dst] = __tzstring (&zone_names[idx]);
+
+ if (__tzname[1 - dst] != NULL)
+ break;
+ }
+ }
+ if (__tzname[0] == NULL)
+ {
+ /* This should only happen if there are no transition rules.
+ In this case there should be only one single type. */
+ assert (num_types == 1);
+ __tzname[0] = __tzstring (zone_names);
+ }
if (__tzname[1] == NULL)
/* There is no daylight saving time. */
__tzname[1] = __tzname[0];
internal_function
compute_tzname_max (size_t chars)
{
- extern size_t __tzname_cur_max; /* Defined in tzset.c. */
-
const char *p;
p = zone_names;