+2005-06-27 Hrvoje Niksic <hniksic@xemacs.org>
+
+ * main.c (i18n_initialize): Set all locale categories.
+
+ * http.c (http_atotm): Temporarily set locale to "C".
+
2005-06-27 Hrvoje Niksic <hniksic@xemacs.org>
* http.c (gethttp): Improve "POST data file missing" error
#include <assert.h>
#include <errno.h>
#include <time.h>
+#include <locale.h>
#include "wget.h"
#include "utils.h"
(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++)
{
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;
}
\f
/* Authorization support: We support three authorization schemes:
/* 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");