From 2254e5c4e41f5d857ed503eed5bd3ad502b62401 Mon Sep 17 00:00:00 2001 From: hniksic Date: Sun, 26 Jun 2005 19:06:52 -0700 Subject: [PATCH] [svn] Set all locale categories. --- src/ChangeLog | 6 ++++++ src/http.c | 25 ++++++++++++++++--------- src/main.c | 13 ------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6e7df87b..38596986 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2005-06-27 Hrvoje Niksic + + * main.c (i18n_initialize): Set all locale categories. + + * http.c (http_atotm): Temporarily set locale to "C". + 2005-06-27 Hrvoje Niksic * http.c (gethttp): Improve "POST data file missing" error diff --git a/src/http.c b/src/http.c index 02519cfd..8a33a29b 100644 --- a/src/http.c +++ b/src/http.c @@ -38,6 +38,7 @@ so, delete this exception statement from your version. */ #include #include #include +#include #include "wget.h" #include "utils.h" @@ -2635,7 +2636,14 @@ http_atotm (const char *time_string) (used in Set-Cookie, defined in the Netscape cookie specification.) */ }; + const char *oldlocale; int i; + time_t ret = (time_t) -1; + + /* Solaris strptime fails to recognize English month names in + non-English locales, which we work around by temporarily setting + locale to C before invoking strptime. */ + oldlocale = setlocale (LC_TIME, "C"); for (i = 0; i < countof (time_formats); i++) { @@ -2646,19 +2654,18 @@ http_atotm (const char *time_string) to prevent garbage from the stack influencing strptime. */ xzero (t); - /* Solaris strptime fails to recognize English month names in - non-English locales, which we work around by not setting the - LC_TIME category. Another way would be to temporarily set - locale to C before invoking strptime, but that's slow and - messy. GNU strptime does not have this problem because it - recognizes English month names along with the local ones. */ - if (check_end (strptime (time_string, time_formats[i], &t))) - return mktime_from_utc (&t); + { + ret = mktime_from_utc (&t); + break; + } } + /* Restore the previous locale. */ + setlocale (LC_TIME, oldlocale); + /* All formats have failed. */ - return -1; + return ret; } /* Authorization support: We support three authorization schemes: diff --git a/src/main.c b/src/main.c index 07f620c3..a6dfbd65 100644 --- a/src/main.c +++ b/src/main.c @@ -79,20 +79,7 @@ i18n_initialize (void) /* HAVE_NLS implies existence of functions invoked here. */ #ifdef HAVE_NLS /* Set the current locale. */ - /* Where possible, sets only LC_MESSAGES and LC_CTYPE. Other - categories, such as numeric, time, or collation, break code that - parses data received from the network and relies on C-locale - behavior of libc functions. For example, Solaris strptime fails - to recognize English month names in non-English locales, which - breaks http_atotm. Some implementations of fnmatch perform - unwanted case folding in non-C locales. ctype macros, while they - were used, provided another example against LC_ALL. */ -#if defined(LC_MESSAGES) && defined(LC_CTYPE) - setlocale (LC_MESSAGES, ""); - setlocale (LC_CTYPE, ""); /* safe because we use safe-ctype */ -#else setlocale (LC_ALL, ""); -#endif /* Set the text message domain. */ bindtextdomain ("wget", LOCALEDIR); textdomain ("wget");