From: Michael Hanselmann Date: Tue, 2 Dec 2008 00:06:00 +0000 (+0100) Subject: Add us_asprintf function X-Git-Tag: 1.0.0-pre1~1959 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=3df9e79877f9131b8a7f9700317a6d86877fbae6;p=vlc Add us_asprintf function us_asprintf() has the same prototype as asprintf(), but doesn't use the system locale. Signed-off-by: Michael Hanselmann Signed-off-by: RĂ©mi Denis-Courmont --- diff --git a/include/vlc_charset.h b/include/vlc_charset.h index 5d3a1b5c93..6e5c4d7b32 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 c8d40bab8f..24e5fc54d0 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 eaed11be71..6d4d2a7b40 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; +}