[vlc-devel] [PATCH 1/2] Add us_asprintf function

Michael Hanselmann public at hansmi.ch
Tue Dec 2 01:06:00 CET 2008


us_asprintf() has the same prototype as asprintf(), but doesn't use
the system locale.

Signed-off-by: Michael Hanselmann <public at hansmi.ch>
---
 include/vlc_charset.h |    1 +
 src/libvlccore.sym    |    1 +
 src/text/charset.c    |   24 ++++++++++++++++++++++++
 3 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/include/vlc_charset.h b/include/vlc_charset.h
index 5d3a1b5..6e5c4d7 100644
--- a/include/vlc_charset.h
+++ b/include/vlc_charset.h
@@ -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
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index c8d40ba..24e5fc5 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -396,6 +396,7 @@ update_GetRelease
 update_NeedUpgrade
 __update_New
 update_WaitDownload
+us_asprintf
 us_atof
 us_strtod
 utf8_fopen
diff --git a/src/text/charset.c b/src/text/charset.c
index eaed11b..6d4d2a7 100644
--- a/src/text/charset.c
+++ b/src/text/charset.c
@@ -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;
+}
-- 
1.5.4.3




More information about the vlc-devel mailing list