]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(STRTOD_L): New macro.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 12 Jul 2004 17:50:11 +0000 (17:50 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 12 Jul 2004 17:50:11 +0000 (17:50 +0000)
(C_STRTOD) [defined LC_ALL_MASK]: Use it, so that the
code is reentrant on platforms that have strtod_l.

lib/c-strtod.c

index 25d8951075214229d0401c4b21ab28fdf72d2606..ae0511034d67c68d0fd711fa965a2e129329aa79 100644 (file)
 #if LONG
 # define C_STRTOD c_strtold
 # define DOUBLE long double
+# define STRTOD_L strtold_l
 #else
 # define C_STRTOD c_strtod
 # define DOUBLE double
+# define STRTOD_L strtod_l
 #endif
 
 /* c_strtold falls back on strtod if strtold isn't declared.  */
@@ -48,6 +50,15 @@ DOUBLE
 C_STRTOD (char const *nptr, char **endptr)
 {
   DOUBLE r;
+
+#ifdef LC_ALL_MASK
+
+  locale_t c_locale = newlocale (LC_ALL_MASK, "C", 0);
+  r = STRTOD_L (nptr, endptr, c_locale);
+  freelocale (c_locale);
+
+#else
+
   char *saved_locale = setlocale (LC_NUMERIC, NULL);
 
   if (saved_locale)
@@ -64,5 +75,7 @@ C_STRTOD (char const *nptr, char **endptr)
       free (saved_locale);
     }
 
+#endif
+
   return r;
 }