macOS: Assume in Xcode project that build exists
[vlc.git] / src / text / charset.c
blob0cb2322654e4360ab770af91c155fe60e5ffb32d
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
9 * RĂ©mi Denis-Courmont
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 *****************************************************************************/
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
30 #include <vlc_common.h>
32 #if !defined _WIN32
33 # include <locale.h>
34 #else
35 # include <windows.h>
36 #endif
38 #ifdef __APPLE__
39 # include <string.h>
40 # include <xlocale.h>
41 #endif
43 #include "libvlc.h"
44 #include <vlc_charset.h>
46 /**
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)
58 uselocale (oldloc);
59 freelocale (loc);
61 return res;
65 /**
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)
77 uselocale (oldloc);
78 freelocale (loc);
80 return res;
84 /**
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 );
94 /**
95 * us_vasprintf() has the same prototype as vasprintf(), but doesn't use
96 * the system locale.
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 )
107 uselocale( oldloc );
108 freelocale( loc );
111 return i_rc;
116 * us_asprintf() has the same prototype as asprintf(), but doesn't use
117 * the system locale.
119 int us_asprintf( char **ret, const char *format, ... )
121 va_list ap;
122 int i_rc;
124 va_start( ap, format );
125 i_rc = us_vasprintf( ret, format, ap );
126 va_end( ap );
128 return i_rc;