Commit 03cd8e02 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Favor libiconv over Win32 API for *Locale

parent a69be9de
...@@ -51,16 +51,17 @@ ...@@ -51,16 +51,17 @@
# define ASSUME_UTF8 1 # define ASSUME_UTF8 1
#endif #endif
#if !(defined (WIN32) || defined (UNDER_CE) || defined (ASSUME_UTF8)) #ifndef ASSUME_UTF8
# define USE_ICONV 1 # if defined (HAVE_ICONV)
#endif /* libiconv is more powerful than Win32 API (it has translit) */
# define USE_ICONV 1
#if defined (USE_ICONV) && !defined (HAVE_ICONV) # elif defined (WIN32) || defined (UNDER_CE)
# error No UTF8 charset conversion implemented on this platform! # define USE_MB2MB 1
# else
# error No UTF8 charset conversion implemented on this platform!
# endif
#endif #endif
#ifdef USE_ICONV #ifdef USE_ICONV
static struct { static struct {
vlc_iconv_t hd; vlc_iconv_t hd;
...@@ -126,7 +127,7 @@ void LocaleDeinit( void ) ...@@ -126,7 +127,7 @@ void LocaleDeinit( void )
#endif #endif
} }
#if defined (WIN32) || defined (UNDER_CE) #ifdef USE_MB2MB
static char *MB2MB( const char *string, UINT fromCP, UINT toCP ) static char *MB2MB( const char *string, UINT fromCP, UINT toCP )
{ {
char *out; char *out;
...@@ -158,7 +159,7 @@ char *FromLocale( const char *locale ) ...@@ -158,7 +159,7 @@ char *FromLocale( const char *locale )
if( locale == NULL ) if( locale == NULL )
return NULL; return NULL;
#if !(defined WIN32 || defined (UNDER_CE)) #ifndef USE_MB2MB
# ifdef USE_ICONV # ifdef USE_ICONV
if( from_locale.hd != (vlc_iconv_t)(-1) ) if( from_locale.hd != (vlc_iconv_t)(-1) )
{ {
...@@ -201,7 +202,7 @@ char *FromLocale( const char *locale ) ...@@ -201,7 +202,7 @@ char *FromLocale( const char *locale )
} }
# endif /* USE_ICONV */ # endif /* USE_ICONV */
return (char *)locale; return (char *)locale;
#else /* WIN32 */ #else /* MB2MB */
return MB2MB( locale, CP_ACP, CP_UTF8 ); return MB2MB( locale, CP_ACP, CP_UTF8 );
#endif #endif
} }
...@@ -228,7 +229,7 @@ char *ToLocale( const char *utf8 ) ...@@ -228,7 +229,7 @@ char *ToLocale( const char *utf8 )
if( utf8 == NULL ) if( utf8 == NULL )
return NULL; return NULL;
#if !(defined (WIN32) || defined (UNDER_CE)) #ifndef USE_MB2MB
# ifdef USE_ICONV # ifdef USE_ICONV
if( to_locale.hd != (vlc_iconv_t)(-1) ) if( to_locale.hd != (vlc_iconv_t)(-1) )
{ {
...@@ -268,7 +269,7 @@ char *ToLocale( const char *utf8 ) ...@@ -268,7 +269,7 @@ char *ToLocale( const char *utf8 )
} }
# endif /* USE_ICONV */ # endif /* USE_ICONV */
return (char *)utf8; return (char *)utf8;
#else /* WIN32 */ #else /* MB2MB */
return MB2MB( utf8, CP_UTF8, CP_ACP ); return MB2MB( utf8, CP_UTF8, CP_ACP );
#endif #endif
} }
...@@ -329,6 +330,10 @@ FILE *utf8_fopen( const char *filename, const char *mode ) ...@@ -329,6 +330,10 @@ FILE *utf8_fopen( const char *filename, const char *mode )
} }
wpath[MAX_PATH] = L'\0'; wpath[MAX_PATH] = L'\0';
/*
* fopen() cannot open files with non-“ANSI” characters on Windows.
* We use _wfopen() instead. Same thing for mkdir() and stat().
*/
return _wfopen( wpath, wmode ); return _wfopen( wpath, wmode );
#endif #endif
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment