[vlc-devel] commit: us_strtod: do not make any kludgy assumptions about number formats ( Rémi Denis-Courmont )
git version control
git at videolan.org
Wed May 21 21:11:47 CEST 2008
vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Wed May 21 22:12:11 2008 +0300| [0b00646d20a3401348b8673b7ec896cd7203a05b]
us_strtod: do not make any kludgy assumptions about number formats
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0b00646d20a3401348b8673b7ec896cd7203a05b
---
src/text/charset.c | 25 +++++++++++--------------
1 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/src/text/charset.c b/src/text/charset.c
index a16d61c..2e7f44a 100644
--- a/src/text/charset.c
+++ b/src/text/charset.c
@@ -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;
}
/**
More information about the vlc-devel
mailing list