]> git.sesse.net Git - vlc/commitdiff
Favor libiconv over Win32 API for *Locale
authorRémi Denis-Courmont <rem@videolan.org>
Tue, 21 Feb 2006 12:49:02 +0000 (12:49 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Tue, 21 Feb 2006 12:49:02 +0000 (12:49 +0000)
src/misc/unicode.c

index c7c2387ddf6db87ba41b086892ba18ce2e3a308a..9504a35a00ed4b42f58c7a4ccff28040fc44fb8d 100644 (file)
 # define ASSUME_UTF8 1
 #endif
 
-#if !(defined (WIN32) || defined (UNDER_CE) || defined (ASSUME_UTF8))
-# define USE_ICONV 1
-#endif
-
-#if defined (USE_ICONV) && !defined (HAVE_ICONV)
-# error No UTF8 charset conversion implemented on this platform!
+#ifndef ASSUME_UTF8
+# if defined (HAVE_ICONV)
+/* libiconv is more powerful than Win32 API (it has translit) */
+#  define USE_ICONV 1
+# elif defined (WIN32) || defined (UNDER_CE)
+#  define USE_MB2MB 1
+# else
+#  error No UTF8 charset conversion implemented on this platform!
+# endif
 #endif
 
-
-
 #ifdef USE_ICONV
 static struct {
     vlc_iconv_t hd;
@@ -126,7 +127,7 @@ void LocaleDeinit( void )
 #endif
 }
 
-#if defined (WIN32) || defined (UNDER_CE)
+#ifdef USE_MB2MB
 static char *MB2MB( const char *string, UINT fromCP, UINT toCP )
 {
     char *out;
@@ -158,7 +159,7 @@ char *FromLocale( const char *locale )
     if( locale == NULL )
         return NULL;
 
-#if !(defined WIN32 || defined (UNDER_CE))
+#ifndef USE_MB2MB
 # ifdef USE_ICONV
     if( from_locale.hd != (vlc_iconv_t)(-1) )
     {
@@ -201,7 +202,7 @@ char *FromLocale( const char *locale )
     }
 # endif /* USE_ICONV */
     return (char *)locale;
-#else /* WIN32 */
+#else /* MB2MB */
     return MB2MB( locale, CP_ACP, CP_UTF8 );
 #endif
 }
@@ -228,7 +229,7 @@ char *ToLocale( const char *utf8 )
     if( utf8 == NULL )
         return NULL;
 
-#if !(defined (WIN32) || defined (UNDER_CE))
+#ifndef USE_MB2MB
 # ifdef USE_ICONV
     if( to_locale.hd != (vlc_iconv_t)(-1) )
     {
@@ -268,7 +269,7 @@ char *ToLocale( const char *utf8 )
     }
 # endif /* USE_ICONV */
     return (char *)utf8;
-#else /* WIN32 */
+#else /* MB2MB */
     return MB2MB( utf8, CP_UTF8, CP_ACP );
 #endif
 }
@@ -329,6 +330,10 @@ FILE *utf8_fopen( const char *filename, const char *mode )
     }
     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 );
 #endif
 }