]> git.sesse.net Git - vlc/commitdiff
Another bunch of Unicode file names fixes (refs #528)
authorRémi Denis-Courmont <rem@videolan.org>
Mon, 13 Feb 2006 09:54:15 +0000 (09:54 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Mon, 13 Feb 2006 09:54:15 +0000 (09:54 +0000)
modules/access/file.c
modules/access/vcd/cdrom.c
modules/access_filter/record.c
modules/access_filter/timeshift.c
modules/audio_output/file.c
modules/control/corba/corba.c
modules/control/http/http.c
modules/control/http/macro.c
modules/control/http/util.c
modules/demux/mp4/drms.c
modules/video_filter/motiondetect.c

index 29fa11cdefe550a33230ea6c5165add2a60f616d..6a5f5e52ba9e55ee5e3ef3f0cd3050bf7b128149 100644 (file)
@@ -164,11 +164,9 @@ static int Open( vlc_object_t *p_this )
     {
         if( psz_name[0] == '~' && psz_name[1] == '/' )
         {
-            psz = malloc( strlen(p_access->p_vlc->psz_homedir)
-                           + strlen(psz_name) );
             /* This is incomplete : we should also support the ~cmassiot/
              * syntax. */
-            sprintf( psz, "%s/%s", p_access->p_vlc->psz_homedir, psz_name + 2 );
+            asprintf( &psz, "%s/%s", p_access->p_vlc->psz_homedir, psz_name + 2 );
             free( psz_name );
             psz_name = psz;
         }
@@ -186,15 +184,12 @@ static int Open( vlc_object_t *p_this )
 #endif
 
 #ifdef HAVE_SYS_STAT_H
-        psz = ToLocale( psz_name );
-        if( stat( psz, &stat_info ) )
+        if( utf8_stat( psz_name, &stat_info ) )
         {
             msg_Warn( p_access, "%s: %s", psz_name, strerror( errno ) );
-            LocaleFree( psz );
             free( psz_name );
             return VLC_EGENERIC;
         }
-        LocaleFree( psz );
 #endif
     }
 
@@ -607,13 +602,9 @@ static int Control( access_t *p_access, int i_query, va_list args )
 static int _OpenFile( access_t * p_access, const char * psz_name )
 {
     access_sys_t *p_sys = p_access->p_sys;
-    const char *psz_localname;
-
-    psz_localname = ToLocale( psz_name );
 
 #ifdef UNDER_CE
-    p_sys->fd = fopen( psz_localname, "rb" );
-    LocaleFree( psz_localname );
+    p_sys->fd = utf8_fopen( psz_name, "rb" );
     if ( !p_sys->fd )
     {
         msg_Err( p_access, "cannot open file %s", psz_name );
@@ -625,6 +616,12 @@ static int _OpenFile( access_t * p_access, const char * psz_name )
     p_access->info.i_update |= INPUT_UPDATE_SIZE;
     fseek( p_sys->fd, 0, SEEK_SET );
 #else
+    const char *psz_localname = ToLocale( psz_name );
+    if( psz_localname == NULL )
+    {
+        msg_Err( p_access, "incorrect file name %s", psz_name );
+        return VLC_EGENERIC;
+    }
 
     p_sys->fd = open( psz_localname, O_NONBLOCK /*| O_LARGEFILE*/ );
     LocaleFree( psz_localname );
index 46d164ffe017b342fd13f1a4b34ab76887c46d95..d1c23a14dd417446dfd2eafedafd579c9bed6c4c 100644 (file)
@@ -858,7 +858,7 @@ static int OpenVCDImage( vlc_object_t * p_this, const char *psz_dev,
 
     /* Open the cue file and try to parse it */
     msg_Dbg( p_this,"trying .cue file: %s", psz_cuefile );
-    cuefile = fopen( psz_cuefile, "rt" );
+    cuefile = utf8_fopen( psz_cuefile, "rt" );
     if( cuefile && fscanf( cuefile, "FILE %c", line ) &&
         fgets( line, 1024, cuefile ) )
     {
index 47989bb7fa14d21d684da5c1efefef9d684bd8f7..a87dedd4a00274679e758fb9e9db55ba44dfea98 100644 (file)
@@ -405,7 +405,7 @@ static void Dump( access_t *p_access, uint8_t *p_buffer, int i_buffer )
 
         msg_Dbg( p_access, "dump in file '%s'", p_sys->psz_file );
 
-        p_sys->f = fopen( p_sys->psz_file, "wb" );
+        p_sys->f = utf8_fopen( p_sys->psz_file, "wb" );
         if( p_sys->f == NULL )
         {
             msg_Err( p_access, "cannot open file '%s' (%s)",
index aa35a6050609fbfc4054a3c370ecb88e34dde9a4..c813352803a55e79da3d81e62930795380a7be92 100644 (file)
@@ -375,7 +375,7 @@ static int WriteBlockToFile( access_t *p_access, block_t *p_block )
 
         sprintf( p_sys->psz_filename, "%s%i.dat",
                  p_sys->psz_filename_base, p_sys->i_files );
-        file = fopen( p_sys->psz_filename, "w+b" );
+        file = utf8_fopen( p_sys->psz_filename, "w+b" );
 
         if( !file && p_sys->i_files < 2 )
         {
index 807ad1d2626149894574bd1d0c67e7d0de3210bd..c97bd77262fbc3498778eb2754c37720473547fe 100644 (file)
@@ -156,7 +156,7 @@ static int Open( vlc_object_t * p_this )
         return VLC_EGENERIC;
     }
 
-    p_aout->output.p_sys->p_file = fopen( psz_name, "wb" );
+    p_aout->output.p_sys->p_file = utf8_fopen( psz_name, "wb" );
     free( psz_name );
     if ( p_aout->output.p_sys->p_file == NULL )
     {
index 3050787a1a2c044b3d5c64905ec566720a632499..a995c46edf59d5cea776e26259e0612239eca10a 100644 (file)
@@ -831,6 +831,8 @@ static void Run( intf_thread_t *p_intf )
     /* We write the IOR in a file. */
     {
         FILE* fp;
+        /* no need for Unicode transliteration as long as VLC_IOR_FILE
+          is pure ASCII */
         fp = fopen( VLC_IOR_FILE, "w" );
         if( fp == NULL )
         {
@@ -843,7 +845,7 @@ static void Run( intf_thread_t *p_intf )
             msg_Warn( p_intf, "IOR written to %s", VLC_IOR_FILE );
         }
     }
-  
+
     root_poa_manager = PortableServer_POA__get_the_POAManager( root_poa, ev );
     handle_exception( "Exception during POAManager resolution" );
 
index 1ce647d0f03111c76923885f8c2b2224b5a5fe9b..36248fed6d3529a9e3dc6a786e10a83570362619 100644 (file)
@@ -91,13 +91,13 @@ static int DirectoryCheck( char *psz_dir )
 #ifdef HAVE_SYS_STAT_H
     struct stat   stat_info;
 
-    if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
+    if( utf8_stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
     {
         return VLC_EGENERIC;
     }
 #endif
 
-    if( ( p_dir = opendir( psz_dir ) ) == NULL )
+    if( ( p_dir = utf8_opendir( psz_dir ) ) == NULL )
     {
         return VLC_EGENERIC;
     }
@@ -571,6 +571,7 @@ int  E_(HttpCallback)( httpd_file_sys_t *p_args,
     char **pp_data = (char **)_pp_data;
     FILE *f;
 
+    /* FIXME: do we need character encoding translation here ? */
     if( ( f = fopen( p_args->file, "r" ) ) == NULL )
     {
         Callback404( p_args, pp_data, pi_data );
index db4c9c3d4fb89a31f2015b19060255d4b1aa7c37..0baad4460d7b791266ee0333c50e436969807054 100644 (file)
@@ -883,6 +883,8 @@ void E_(Execute)( httpd_file_sys_t *p_args,
                         strcpy( psz_file, m.param1 );
                     }
 
+                    /* We hereby assume that psz_file is in the
+                     * local character encoding */
                     if( ( f = fopen( psz_file, "r" ) ) == NULL )
                     {
                         msg_Warn( p_args->p_intf,
index 579da7eaa8e01191ec5ae15ad33aad063451513c..670d922a23767ab4afb3885730676b95b8ca25f4 100644 (file)
@@ -109,7 +109,6 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
     struct stat   stat_info;
 #endif
     DIR           *p_dir;
-    struct dirent *p_dir_content;
     vlc_acl_t     *p_acl;
     FILE          *file;
 
@@ -127,13 +126,13 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
 #endif
 
 #ifdef HAVE_SYS_STAT_H
-    if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
+    if( utf8_stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
     {
         return VLC_EGENERIC;
     }
 #endif
 
-    if( ( p_dir = opendir( psz_dir ) ) == NULL )
+    if( ( p_dir = utf8_opendir( psz_dir ) ) == NULL )
     {
         msg_Err( p_intf, "cannot open dir (%s)", psz_dir );
         return VLC_EGENERIC;
@@ -149,7 +148,7 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
     msg_Dbg( p_intf, "dir=%s", psz_dir );
 
     sprintf( dir, "%s%c.access", psz_dir, sep );
-    if( ( file = fopen( dir, "r" ) ) != NULL )
+    if( ( file = utf8_fopen( dir, "r" ) ) != NULL )
     {
         char line[1024];
         int  i_size;
@@ -192,17 +191,20 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
 
     for( ;; )
     {
+        char *psz_filename;
         /* parse psz_src dir */
-        if( ( p_dir_content = readdir( p_dir ) ) == NULL )
+        if( ( psz_filename = utf8_readdir( p_dir ) ) == NULL )
         {
             break;
         }
 
-        if( ( p_dir_content->d_name[0] == '.' )
-         || ( i_dirlen + strlen( p_dir_content->d_name ) > MAX_DIR_SIZE ) )
+        if( ( psz_filename[0] == '.' )
+         || ( i_dirlen + strlen( psz_filename ) > MAX_DIR_SIZE ) )
             continue;
 
-        sprintf( dir, "%s%c%s", psz_dir, sep, p_dir_content->d_name );
+        sprintf( dir, "%s%c%s", psz_dir, sep, psz_filename );
+        LocaleFree( psz_filename );
+
         if( E_(ParseDirectory)( p_intf, psz_root, dir ) )
         {
             httpd_file_sys_t *f = NULL;
index 32d91ecabd678b97e65edbfb840d59520feef487..d66a9aa3b540197c4f42f3527743cf4570d7e740 100644 (file)
@@ -1580,7 +1580,7 @@ static int WriteUserKey( void *_p_drms, uint32_t *p_user_key )
         snprintf( psz_path, PATH_MAX - 1, "%s/" DRMS_DIRNAME "/%08X.%03d",
                   p_drms->psz_homedir, p_drms->i_user, p_drms->i_key );
 
-        file = fopen( psz_path, "wb" );
+        file = utf8_fopen( psz_path, "wb" );
         if( file != NULL )
         {
             i_ret = fwrite( p_user_key, sizeof(uint32_t),
@@ -1608,7 +1608,7 @@ static int ReadUserKey( void *_p_drms, uint32_t *p_user_key )
               "%s/" DRMS_DIRNAME "/%08X.%03d", p_drms->psz_homedir,
               p_drms->i_user, p_drms->i_key );
 
-    file = fopen( psz_path, "rb" );
+    file = utf8_fopen( psz_path, "rb" );
     if( file != NULL )
     {
         i_ret = fread( p_user_key, sizeof(uint32_t),
@@ -1773,7 +1773,7 @@ static int GetSCIData( char *psz_ipod, uint32_t **pp_sci,
 {
     FILE *file;
     char *psz_path = NULL;
-    char p_tmp[ PATH_MAX ];
+    char p_tmp[ 4 * PATH_MAX ];
     int i_ret = -1;
 
     if( psz_ipod == NULL )
@@ -1799,7 +1799,12 @@ static int GetSCIData( char *psz_ipod, uint32_t **pp_sci,
             strncat( p_tmp, p_filename, min( strlen( p_filename ),
                      (sizeof(p_tmp)/sizeof(p_tmp[0]) - 1) -
                      strlen( p_tmp ) ) );
-            psz_path = p_tmp;
+
+            psz_path = FromLocale( p_tmp );
+            strncpy( psz_tmp, sizeof( psz_tmp ) - 1, psz_path );
+            psz_tmp[sizeof( psz_tmp ) - 1] = '\0';
+            LocaleFree( psz_path );
+            psz_path = psz_tmp;
         }
 
         if( shfolder_dll != NULL )
@@ -1828,7 +1833,7 @@ static int GetSCIData( char *psz_ipod, uint32_t **pp_sci,
         return -1;
     }
 
-    file = fopen( psz_path, "rb" );
+    file = utf8_fopen( psz_path, "rb" );
     if( file != NULL )
     {
         struct stat st;
index fb4bf56856743ef1a90b8a05e70cdea165753618..37abd9ce5c3375b44b521b1fe9b176e1d42a5ca6 100644 (file)
@@ -158,7 +158,7 @@ static int Create( vlc_object_t *p_this )
     }
 
     /* Parse description file and allocate areas */
-    p_file = fopen( psz_descfilename, "r" );
+    p_file = utf8_fopen( psz_descfilename, "r" );
     if( !p_file )
     {
         msg_Err( p_this, "Failed to open descritpion file %s",