1 /*****************************************************************************
2 * charset.c: Locale's character encoding stuff.
3 *****************************************************************************
4 * See also unicode.c for Unicode to locale conversion helpers.
6 * Copyright (C) 2003-2008 VLC authors and VideoLAN
8 * Authors: Christophe Massiot
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
30 #include <vlc_common.h>
44 #include <vlc_charset.h>
47 * us_strtod() has the same prototype as ANSI C strtod() but it uses the
48 * POSIX/C decimal format, regardless of the current numeric locale.
50 double us_strtod( const char *str, char **end )
52 locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
53 locale_t oldloc = uselocale (loc);
54 double res = strtod (str, end);
56 if (loc != (locale_t)0)
66 * us_strtof() has the same prototype as ANSI C strtof() but it uses the
67 * POSIX/C decimal format, regardless of the current numeric locale.
69 float us_strtof( const char *str, char **end )
71 locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
72 locale_t oldloc = uselocale (loc);
73 float res = strtof (str, end);
75 if (loc != (locale_t)0)
85 * us_atof() has the same prototype as ANSI C atof() but it expects a dot
86 * as decimal separator, regardless of the system locale.
88 double us_atof( const char *str )
90 return us_strtod( str, NULL );
95 * us_vasprintf() has the same prototype as vasprintf(), but doesn't use
98 int us_vasprintf( char **ret, const char *format, va_list ap )
100 locale_t loc = newlocale( LC_NUMERIC_MASK, "C", NULL );
101 locale_t oldloc = uselocale( loc );
103 int i_rc = vasprintf( ret, format, ap );
105 if ( loc != (locale_t)0 )
116 * us_asprintf() has the same prototype as asprintf(), but doesn't use
119 int us_asprintf( char **ret, const char *format, ... )
124 va_start( ap, format );
125 i_rc = us_vasprintf( ret, format, ap );