]> git.sesse.net Git - vlc/commitdiff
Add us_asprintf function
authorMichael Hanselmann <public@hansmi.ch>
Tue, 2 Dec 2008 00:06:00 +0000 (01:06 +0100)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Tue, 2 Dec 2008 17:03:57 +0000 (19:03 +0200)
us_asprintf() has the same prototype as asprintf(), but doesn't use
the system locale.

Signed-off-by: Michael Hanselmann <public@hansmi.ch>
Signed-off-by: Rémi Denis-Courmont <rdenis@simphalempin.com>
include/vlc_charset.h
src/libvlccore.sym
src/text/charset.c

index 5d3a1b5c93c67c407eef22c1eab2ba3dcea9a163..6e5c4d7b325ef2ac36b367723c6cf7253756bd87 100644 (file)
@@ -85,5 +85,6 @@ VLC_EXPORT( const char *, GetFallbackEncoding, ( void ) LIBVLC_USED );
 
 VLC_EXPORT( double, us_strtod, ( const char *, char ** ) LIBVLC_USED );
 VLC_EXPORT( double, us_atof, ( const char * ) LIBVLC_USED );
+VLC_EXPORT( int, us_asprintf, ( char **, const char *, ... ) LIBVLC_USED );
 
 #endif
index c8d40bab8ffbc0a838e2b698484dc0d20c763470..24e5fc54d086e0b54ffbe7329ad3035d241820c5 100644 (file)
@@ -396,6 +396,7 @@ update_GetRelease
 update_NeedUpgrade
 __update_New
 update_WaitDownload
+us_asprintf
 us_atof
 us_strtod
 utf8_fopen
index eaed11be71e2ed85178c36736d4c79b9216a25ec..6d4d2a7b4030f64b3d1c249cde0c29144c99babc 100644 (file)
@@ -100,3 +100,27 @@ double us_atof( const char *str )
     return us_strtod( str, NULL );
 }
 
+
+/**
+ * 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;
+    locale_t loc = newlocale( LC_NUMERIC_MASK, "C", NULL );
+    locale_t oldloc = uselocale( loc );
+    int i_rc;
+
+    va_start( ap, format );
+    i_rc = vasprintf( ret, format, ap );
+    va_end( ap );
+
+    if ( loc != (locale_t)0 )
+    {
+        uselocale( oldloc );
+        freelocale( loc );
+    }
+
+    return i_rc;
+}