* time/tzset.c (__tzset_parse_tz): Use correct string when parsing

DST name.
	* time/tst-posixtz.c: Add tests for quoted timezone names.
This commit is contained in:
Ulrich Drepper 2009-03-10 15:23:46 +00:00
parent 7db0cc4245
commit 686f8c9daf
3 changed files with 45 additions and 12 deletions

View File

@ -1,3 +1,9 @@
2009-03-10 Ulrich Drepper <drepper@redhat.com>
* time/tzset.c (__tzset_parse_tz): Use correct string when parsing
DST name.
* time/tst-posixtz.c: Add tests for quoted timezone names.
2009-03-10 Jakub Jelinek <jakub@redhat.com> 2009-03-10 Jakub Jelinek <jakub@redhat.com>
* posix/unistd.h (_POSIX_VERSION, _POSIX2_VERSION, _POSIX2_C_BIND, * posix/unistd.h (_POSIX_VERSION, _POSIX2_VERSION, _POSIX2_C_BIND,

View File

@ -18,6 +18,10 @@ struct
"1999/02/26 07:18:12 dst=1 zone=AEDST" }, "1999/02/26 07:18:12 dst=1 zone=AEDST" },
{ 909312849L, "EST+5EDT,M4.1.0/2,M10.5.0/2", { 909312849L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
"1998/10/25 05:54:09 dst=0 zone=EST" }, "1998/10/25 05:54:09 dst=0 zone=EST" },
{ 909312849L, "EST5EDT,M4.1.0/2,M10.5.0/2",
"1998/10/25 05:54:09 dst=0 zone=EST" },
{ 909312849L, "<EST5>5EDT,M4.1.0/2,M10.5.0/2",
"1998/10/25 05:54:09 dst=0 zone=EST5" },
{ 924864849L, "EST+5EDT,M4.1.0/2,M10.5.0/2", { 924864849L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
"1999/04/23 06:54:09 dst=1 zone=EDT" }, "1999/04/23 06:54:09 dst=1 zone=EDT" },
{ 919973892L, "EST+5EDT,M4.1.0/2,M10.5.0/2", { 919973892L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
@ -84,5 +88,31 @@ main (void)
puts (", FAIL"); puts (", FAIL");
} }
setenv ("TZ", "<AB1>-10<AB2>-11,M10.5.0,M3.5.0", 1);
tzset ();
printf ("TZ = \"<AB1>-10<AB2>-11,M10.5.0,M3.5.0\" daylight %d"
" tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]);
if (daylight
&& strcmp (tzname[0], "AB1") == 0 && strcmp (tzname[1], "AB2") == 0)
puts (", OK");
else
{
result = 1;
puts (", FAIL");
}
setenv ("TZ", "<BB1>-10", 1);
tzset ();
printf ("TZ = \"<BB1>-10\" daylight %d"
" tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]);
if (daylight == 0
&& strcmp (tzname[0], "BB1") == 0 && strcmp (tzname[1], "BB1") == 0)
puts (", OK");
else
{
result = 1;
puts (", FAIL");
}
return result; return result;
} }

View File

@ -163,7 +163,6 @@ __tzset_parse_tz (tz)
const char *tz; const char *tz;
{ {
register size_t l; register size_t l;
char *tzbuf;
unsigned short int hh, mm, ss; unsigned short int hh, mm, ss;
unsigned short int whichrule; unsigned short int whichrule;
@ -172,22 +171,22 @@ __tzset_parse_tz (tz)
tz_rules[0].name = tz_rules[1].name = ""; tz_rules[0].name = tz_rules[1].name = "";
/* Get the standard timezone name. */ /* Get the standard timezone name. */
tzbuf = strdupa (tz); char *tzbuf = strdupa (tz);
if (sscanf (tz, "%[A-Za-z]", tzbuf) != 1) if (sscanf (tz, "%[A-Za-z]", tzbuf) != 1)
{ {
/* Check for the quoted version. */ /* Check for the quoted version. */
char *wp = tzbuf; char *wp = tzbuf;
if (*tz++ != '<') if (__builtin_expect (*tz++ != '<', 0))
goto out; goto out;
while (isalnum (*tz) || *tz == '+' || *tz == '-') while (isalnum (*tz) || *tz == '+' || *tz == '-')
*wp++ = *tz++; *wp++ = *tz++;
if (*tz++ != '>' || wp - tzbuf < 3) if (__builtin_expect (*tz++ != '>' || wp - tzbuf < 3, 0))
goto out; goto out;
*wp = '\0'; *wp = '\0';
} }
else if ((l = strlen (tzbuf)) < 3) else if (__builtin_expect ((l = strlen (tzbuf)) < 3, 0))
goto out; goto out;
else else
tz += l; tz += l;
@ -219,7 +218,7 @@ __tzset_parse_tz (tz)
for (l = 0; l < 3; ++l) for (l = 0; l < 3; ++l)
{ {
while (isdigit(*tz)) while (isdigit (*tz))
++tz; ++tz;
if (l < 2 && *tz == ':') if (l < 2 && *tz == ':')
++tz; ++tz;
@ -228,32 +227,30 @@ __tzset_parse_tz (tz)
/* Get the DST timezone name (if any). */ /* Get the DST timezone name (if any). */
if (*tz != '\0') if (*tz != '\0')
{ {
char *n = tzbuf + strlen (tzbuf) + 1;
if (sscanf (tz, "%[A-Za-z]", tzbuf) != 1) if (sscanf (tz, "%[A-Za-z]", tzbuf) != 1)
{ {
/* Check for the quoted version. */ /* Check for the quoted version. */
char *wp = tzbuf; char *wp = tzbuf;
const char *rp = tz; const char *rp = tz;
if (*rp++ != '<') if (__builtin_expect (*rp++ != '<', 0))
/* Punt on name, set up the offsets. */ /* Punt on name, set up the offsets. */
goto done_names; goto done_names;
while (isalnum (*rp) || *rp == '+' || *rp == '-') while (isalnum (*rp) || *rp == '+' || *rp == '-')
*wp++ = *rp++; *wp++ = *rp++;
if (*rp++ != '>' || wp - tzbuf < 3) if (__builtin_expect (*rp++ != '>' || wp - tzbuf < 3, 0))
/* Punt on name, set up the offsets. */ /* Punt on name, set up the offsets. */
goto done_names; goto done_names;
*wp = '\0'; *wp = '\0';
tz = rp; tz = rp;
} }
else if ((l = strlen (tzbuf)) < 3) else if (__builtin_expect ((l = strlen (tzbuf)) < 3, 0))
/* Punt on name, set up the offsets. */ /* Punt on name, set up the offsets. */
goto done_names; goto done_names;
else else
tz += l; tz += l;
tz_rules[1].name = __tzstring (n); tz_rules[1].name = __tzstring (tzbuf);
/* Figure out the DST offset from GMT. */ /* Figure out the DST offset from GMT. */
if (*tz == '-' || *tz == '+') if (*tz == '-' || *tz == '+')