]> git.sesse.net Git - vlc/commitdiff
us_strtod: do not make any kludgy assumptions about number formats
authorRémi Denis-Courmont <rem@videolan.org>
Wed, 21 May 2008 19:12:11 +0000 (22:12 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Wed, 21 May 2008 19:12:24 +0000 (22:12 +0300)
src/text/charset.c

index a16d61c94ac51e1fbe1ebe46aaaef71ef9b57047..2e7f44a3944cd8c30e9489b690f7386d54a8efc9 100644 (file)
@@ -378,24 +378,21 @@ char *vlc_fix_readdir( const char *psz_string )
 
 
 /**
- * us_strtod() has the same prototype as ANSI C strtod() but it expects
- * a dot as decimal separator regardless of the system locale.
+ * us_strtod() has the same prototype as ANSI C strtod() but it uses the
+ * POSIX/C decimal format, regardless of the current numeric locale.
  */
 double us_strtod( const char *str, char **end )
 {
-    char dup[strlen( str ) + 1], *ptr;
-    double d;
-    strcpy( dup, str );
+    locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
+    locale_t oldloc = uselocale (loc);
+    double res = strtod (str, end);
 
-    ptr = strchr( dup, ',' );
-    if( ptr != NULL )
-        *ptr = '\0';
-
-    d = strtod( dup, &ptr );
-    if( end != NULL )
-        *end = (char *)&str[ptr - dup];
-
-    return d;
+    if (loc != (locale_t)0)
+    {
+        uselocale (oldloc);
+        freelocale (loc);
+    }
+    return res;
 }
 
 /**