]> git.sesse.net Git - vlc/blobdiff - src/text/unicode.c
Remove the Rating column from the inteface because with don't save any information...
[vlc] / src / text / unicode.c
index b9d62074cba54d751091bfbafed8891ee147ee28..e01c1d757d448f96be823480616a3b551efd5686 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include <vlc_charset.h>
+#include "libvlc.h" /* utf8_mkdir */
 
 #include <assert.h>
 
@@ -80,6 +85,7 @@ static void find_charset_once (void)
     char *psz_charset;
     if (vlc_current_charset (&psz_charset)
      || (psz_charset == NULL)
+     || (strcmp (psz_charset, "ASCII") == 0)
      || ((size_t)snprintf (charset, sizeof (charset), "%s//translit",
                            psz_charset) >= sizeof (charset)))
         strcpy (charset, "UTF-8");
@@ -142,15 +148,16 @@ static char *locale_fast (const char *string, vlc_bool_t from)
                                    0, string, -1, NULL, 0);
     wchar_t wide[len];
 
-    MultiByteToWideChar (from ? CP_UTF8 : CP_ACP, 0, string, -1, wide, len);
-    len = 1 + WideCharToMultiByte (p->toCP, 0, wide, -1, NULL, 0, NULL, NULL);
+    MultiByteToWideChar (from ? CP_ACP : CP_UTF8, 0, string, -1, wide, len);
+    len = 1 + WideCharToMultiByte (from ? CP_UTF8 : CP_ACP, 0, wide, -1, NULL, 0, NULL, NULL);
     out = malloc (len);
     if (out == NULL)
         return NULL;
 
-    WideCharToMultiByte (p->toCP, 0, wide, -1, out, len, NULL, NULL);
+    WideCharToMultiByte (from ? CP_UTF8 : CP_ACP, 0, wide, -1, out, len, NULL, NULL);
     return out;
 #else
+    VLC_UNUSED(from);
     return (char *)string;
 #endif
 }
@@ -165,6 +172,7 @@ static inline char *locale_dup (const char *string, vlc_bool_t from)
 #elif defined (USE_MB2MB)
     return locale_fast (string, from);
 #else
+    VLC_UNUSED(from);
     return strdup (string);
 #endif
 }
@@ -173,10 +181,12 @@ static inline char *locale_dup (const char *string, vlc_bool_t from)
 void LocaleFree (const char *str)
 {
 #if defined (USE_ICONV)
-    if (find_charset ())
+    if (!find_charset ())
         free ((char *)str);
 #elif defined (USE_MB2MB)
     free ((char *)str);
+#else
+    VLC_UNUSED(str);
 #endif
 }
 
@@ -324,7 +334,7 @@ FILE *utf8_fopen (const char *filename, const char *mode)
  * @return A 0 return value indicates success. A -1 return value indicates an
  *        error, and an error code is stored in errno
  */
-int utf8_mkdir( const char *dirname )
+int utf8_mkdir( const char *dirname, mode_t mode )
 {
 #if defined (UNDER_CE) || defined (WIN32)
     wchar_t wname[MAX_PATH + 1];
@@ -371,7 +381,7 @@ int utf8_mkdir( const char *dirname )
         errno = ENOENT;
         return -1;
     }
-    res = mkdir( locname, 0755 );
+    res = mkdir( locname, mode );
 
     LocaleFree( locname );
     return res;
@@ -416,7 +426,7 @@ DIR *utf8_opendir( const char *dirname )
  *
  * @param dir The directory that is being read
  *
- * @return a UTF-8 string of the directory entry. Use LocaleFree() to free this memory
+ * @return a UTF-8 string of the directory entry. Use free() to free this memory.
  */
 char *utf8_readdir( DIR *dir )
 {
@@ -560,6 +570,50 @@ int utf8_lstat( const char *filename, struct stat *buf)
     return utf8_statEx( filename, buf, VLC_FALSE );
 }
 
+/**
+ * utf8_unlink: Calls unlink() after conversion of file name to OS locale
+ *
+ * @param filename a UTF-8 string with the name of the file you want to delete.
+ * @return A 0 return value indicates success. A -1 return value indicates an
+ *        error, and an error code is stored in errno
+ */
+int utf8_unlink( const char *filename )
+{
+#if defined (WIN32) || defined (UNDER_CE)
+    if( GetVersion() < 0x80000000 )
+    {
+        /* for Windows NT and above */
+        wchar_t wpath[MAX_PATH + 1];
+
+        if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH ) )
+        {
+            errno = ENOENT;
+            return -1;
+        }
+        wpath[MAX_PATH] = L'\0';
+
+        /*
+         * unlink() cannot open files with non-“ANSI” characters on Windows.
+         * We use _wunlink() instead.
+         */
+        return _wunlink( wpath );
+    }
+#endif
+    const char *local_name = ToLocale( filename );
+
+    if( local_name == NULL )
+    {
+        errno = ENOENT;
+        return -1;
+    }
+
+    int ret = unlink( local_name );
+    LocaleFree( local_name );
+    return ret;
+}
+
+
+
 /**
  * utf8_*printf: *printf with conversion from UTF-8 to local encoding
  */