diff --git a/src/time/__tz.c b/src/time/__tz.c index 54ed4cf6..e7ac0da7 100644 --- a/src/time/__tz.c +++ b/src/time/__tz.c @@ -436,3 +436,22 @@ const char *__tm_to_tzname(const struct tm *tm) UNLOCK(lock); return p; } + +int __tzname_to_isdst(const char **s) +{ + size_t len; + int isdst = -1; + LOCK(lock); + if (tzname[0] && !strncmp(*s, tzname[0], len = strlen(tzname[0]))) { + isdst = 0; + s += len; + } else if (tzname[1] && !strncmp(*s, tzname[1], len=strlen(tzname[1]))) { + isdst = 1; + s += len; + } else { + /* FIXME: is this supposed to be an error? */ + while ((**s|32)-'a' <= 'z'-'a') ++*s; + } + UNLOCK(lock); + return isdst; +} diff --git a/src/time/strptime.c b/src/time/strptime.c index b1147242..4a6df8b5 100644 --- a/src/time/strptime.c +++ b/src/time/strptime.c @@ -5,11 +5,12 @@ #include #include #include +#include "time_impl.h" char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm) { int i, w, neg, adj, min, range, *dest, dummy; - const char *ex; + const char *ex, *s1; size_t len; int want_century = 0, century = 0, relyear = 0; while (*f) { @@ -207,16 +208,10 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri s += 5; break; case 'Z': - if (!strncmp(s, tzname[0], len = strlen(tzname[0]))) { - tm->tm_isdst = 0; - s += len; - } else if (!strncmp(s, tzname[1], len=strlen(tzname[1]))) { - tm->tm_isdst = 1; - s += len; - } else { - /* FIXME: is this supposed to be an error? */ - while ((*s|32)-'a' <= 'z'-'a') s++; - } + s1 = s; + i = __tzname_to_isdst(&s1); + if (i>=0) tm->tm_isdst = i; + s = s1; break; case '%': if (*s++ != '%') return 0; diff --git a/src/time/time_impl.h b/src/time/time_impl.h index f26d8005..5449a622 100644 --- a/src/time/time_impl.h +++ b/src/time/time_impl.h @@ -5,6 +5,7 @@ hidden int __month_to_secs(int, int); hidden long long __year_to_secs(long long, int *); hidden long long __tm_to_secs(const struct tm *); hidden const char *__tm_to_tzname(const struct tm *); +hidden int __tzname_to_isdst(const char **); hidden int __secs_to_tm(long long, struct tm *); hidden void __secs_to_zone(long long, int, int *, long *, long *, const char **); hidden const char *__strftime_fmt_1(char (*)[100], size_t *, int, const struct tm *, locale_t, int);