]> sjero.net Git - wget/commitdiff
[svn] Set all locale categories.
authorhniksic <devnull@localhost>
Mon, 27 Jun 2005 02:06:52 +0000 (19:06 -0700)
committerhniksic <devnull@localhost>
Mon, 27 Jun 2005 02:06:52 +0000 (19:06 -0700)
src/ChangeLog
src/http.c
src/main.c

index 6e7df87bd7b3537f386c78521f6edc7576da078f..385969863fcf3dbee6b39b4ff93034b1bb7d6f92 100644 (file)
@@ -1,3 +1,9 @@
+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
index 02519cfd938487fa49b044b58a7bbf79c8c08b61..8a33a29b149b9a0137d2e49343d3c4955bc8c309 100644 (file)
@@ -38,6 +38,7 @@ so, delete this exception statement from your version.  */
 #include <assert.h>
 #include <errno.h>
 #include <time.h>
+#include <locale.h>
 
 #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;
 }
 \f
 /* Authorization support: We support three authorization schemes:
index 07f620c343f85212033ac2f5253f5bf7b6e20a69..a6dfbd65593e9bb73fb84679830014327f129317 100644 (file)
@@ -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");