[vlc-devel] commit: Add a us_strtof function to prevent some problem ( Cyril Mathé )

git version control git at videolan.org
Fri Apr 17 19:49:56 CEST 2009


vlc | branch: master | Cyril Mathé <cmathe at actech-innovation.com> | Tue Apr 14 11:48:33 2009 +0200| [7158759483ba92bf8d226981c1d39aaab54b71ff] | committer: Rémi Denis-Courmont 

Add a us_strtof function to prevent some problem

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7158759483ba92bf8d226981c1d39aaab54b71ff
---

 include/vlc_charset.h |    1 +
 src/libvlccore.sym    |    1 +
 src/text/charset.c    |   20 ++++++++++++++++++++
 3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/include/vlc_charset.h b/include/vlc_charset.h
index ddd50df..cae46c7 100644
--- a/include/vlc_charset.h
+++ b/include/vlc_charset.h
@@ -111,6 +111,7 @@ static inline char *FromLatin1 (const char *latin)
 VLC_EXPORT( const char *, GetFallbackEncoding, ( void ) LIBVLC_USED );
 
 VLC_EXPORT( double, us_strtod, ( const char *, char ** ) LIBVLC_USED );
+VLC_EXPORT( float, us_strtof, ( const char *, char ** ) LIBVLC_USED );
 VLC_EXPORT( double, us_atof, ( const char * ) LIBVLC_USED );
 VLC_EXPORT( int, us_asprintf, ( char **, const char *, ... ) LIBVLC_USED );
 
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index af5a6b1..77a494c 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -385,6 +385,7 @@ update_WaitDownload
 us_asprintf
 us_atof
 us_strtod
+us_strtof
 utf8_fopen
 utf8_fprintf
 utf8_loaddir
diff --git a/src/text/charset.c b/src/text/charset.c
index 6d4d2a7..7812cb9 100644
--- a/src/text/charset.c
+++ b/src/text/charset.c
@@ -91,6 +91,26 @@ double us_strtod( const char *str, char **end )
     return res;
 }
 
+
+/**
+ * us_strtof() has the same prototype as ANSI C strtof() but it uses the
+ * POSIX/C decimal format, regardless of the current numeric locale.
+ */
+float us_strtof( const char *str, char **end )
+{
+    locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
+    locale_t oldloc = uselocale (loc);
+    float res = strtof (str, end);
+
+    if (loc != (locale_t)0)
+    {
+        uselocale (oldloc);
+        freelocale (loc);
+    }
+    return res;
+}
+
+
 /**
  * us_atof() has the same prototype as ANSI C atof() but it expects a dot
  * as decimal separator, regardless of the system locale.




More information about the vlc-devel mailing list