]> git.sesse.net Git - vlc/blobdiff - src/text/charset.c
Add a mailmap
[vlc] / src / text / charset.c
index eaed11be71e2ed85178c36736d4c79b9216a25ec..edb5dae8ca506c6b2c770cf3fcd71d0ec5f80cb1 100644 (file)
@@ -36,7 +36,6 @@
 #endif
 
 #ifdef __APPLE__
-#   include <errno.h>
 #   include <string.h>
 #   include <xlocale.h>
 #endif
 #include "libvlc.h"
 #include <vlc_charset.h>
 
-char *vlc_fix_readdir( const char *psz_string )
+/**
+ * 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 )
 {
-#ifdef __APPLE__
-    vlc_iconv_t hd = vlc_iconv_open( "UTF-8", "UTF-8-MAC" );
+    locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
+    locale_t oldloc = uselocale (loc);
+    double res = strtod (str, end);
 
-    if (hd != (vlc_iconv_t)(-1))
+    if (loc != (locale_t)0)
     {
-        const char *psz_in = psz_string;
-        size_t i_in = strlen(psz_in);
-        size_t i_out = i_in * 2;
-        char *psz_utf8 = malloc(i_out + 1);
-        char *psz_out = psz_utf8;
-
-        size_t i_ret = vlc_iconv (hd, &psz_in, &i_in, &psz_out, &i_out);
-        vlc_iconv_close (hd);
-        if( i_ret == (size_t)(-1) || i_in )
-        {
-            free( psz_utf8 );
-            return strdup( psz_string );
-        }
-
-        *psz_out = '\0';
-        return psz_utf8;
+        uselocale (oldloc);
+        freelocale (loc);
     }
-#endif
-    return strdup( psz_string );
+    return res;
 }
 
 
 /**
- * us_strtod() has the same prototype as ANSI C strtod() but it uses the
+ * us_strtof() has the same prototype as ANSI C strtof() but it uses the
  * POSIX/C decimal format, regardless of the current numeric locale.
  */
-double us_strtod( const char *str, char **end )
+float us_strtof( const char *str, char **end )
 {
     locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
     locale_t oldloc = uselocale (loc);
-    double res = strtod (str, end);
+    float res = strtof (str, end);
 
     if (loc != (locale_t)0)
     {
@@ -91,6 +80,7 @@ double us_strtod( const char *str, char **end )
     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.
@@ -100,3 +90,40 @@ double us_atof( const char *str )
     return us_strtod( str, NULL );
 }
 
+
+/**
+ * us_vasprintf() has the same prototype as vasprintf(), but doesn't use
+ * the system locale.
+ */
+int us_vasprintf( char **ret, const char *format, va_list ap )
+{
+    locale_t loc = newlocale( LC_NUMERIC_MASK, "C", NULL );
+    locale_t oldloc = uselocale( loc );
+
+    int i_rc = vasprintf( ret, format, ap );
+
+    if ( loc != (locale_t)0 )
+    {
+        uselocale( oldloc );
+        freelocale( loc );
+    }
+
+    return i_rc;
+}
+
+
+/**
+ * us_asprintf() has the same prototype as asprintf(), but doesn't use
+ * the system locale.
+ */
+int us_asprintf( char **ret, const char *format, ... )
+{
+    va_list ap;
+    int i_rc;
+
+    va_start( ap, format );
+    i_rc = us_vasprintf( ret, format, ap );
+    va_end( ap );
+
+    return i_rc;
+}