From 543574fd1d30e5be90ec4adcc9d15046c90af350 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Mon, 13 Feb 2006 09:54:15 +0000 Subject: [PATCH] Another bunch of Unicode file names fixes (refs #528) --- modules/access/file.c | 21 +++++++++------------ modules/access/vcd/cdrom.c | 2 +- modules/access_filter/record.c | 2 +- modules/access_filter/timeshift.c | 2 +- modules/audio_output/file.c | 2 +- modules/control/corba/corba.c | 4 +++- modules/control/http/http.c | 5 +++-- modules/control/http/macro.c | 2 ++ modules/control/http/util.c | 18 ++++++++++-------- modules/demux/mp4/drms.c | 15 ++++++++++----- modules/video_filter/motiondetect.c | 2 +- 11 files changed, 42 insertions(+), 33 deletions(-) diff --git a/modules/access/file.c b/modules/access/file.c index 29fa11cdef..6a5f5e52ba 100644 --- a/modules/access/file.c +++ b/modules/access/file.c @@ -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 ); diff --git a/modules/access/vcd/cdrom.c b/modules/access/vcd/cdrom.c index 46d164ffe0..d1c23a14dd 100644 --- a/modules/access/vcd/cdrom.c +++ b/modules/access/vcd/cdrom.c @@ -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 ) ) { diff --git a/modules/access_filter/record.c b/modules/access_filter/record.c index 47989bb7fa..a87dedd4a0 100644 --- a/modules/access_filter/record.c +++ b/modules/access_filter/record.c @@ -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)", diff --git a/modules/access_filter/timeshift.c b/modules/access_filter/timeshift.c index aa35a60506..c813352803 100644 --- a/modules/access_filter/timeshift.c +++ b/modules/access_filter/timeshift.c @@ -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 ) { diff --git a/modules/audio_output/file.c b/modules/audio_output/file.c index 807ad1d262..c97bd77262 100644 --- a/modules/audio_output/file.c +++ b/modules/audio_output/file.c @@ -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 ) { diff --git a/modules/control/corba/corba.c b/modules/control/corba/corba.c index 3050787a1a..a995c46edf 100644 --- a/modules/control/corba/corba.c +++ b/modules/control/corba/corba.c @@ -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" ); diff --git a/modules/control/http/http.c b/modules/control/http/http.c index 1ce647d0f0..36248fed6d 100644 --- a/modules/control/http/http.c +++ b/modules/control/http/http.c @@ -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 ); diff --git a/modules/control/http/macro.c b/modules/control/http/macro.c index db4c9c3d4f..0baad4460d 100644 --- a/modules/control/http/macro.c +++ b/modules/control/http/macro.c @@ -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, diff --git a/modules/control/http/util.c b/modules/control/http/util.c index 579da7eaa8..670d922a23 100644 --- a/modules/control/http/util.c +++ b/modules/control/http/util.c @@ -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; diff --git a/modules/demux/mp4/drms.c b/modules/demux/mp4/drms.c index 32d91ecabd..d66a9aa3b5 100644 --- a/modules/demux/mp4/drms.c +++ b/modules/demux/mp4/drms.c @@ -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; diff --git a/modules/video_filter/motiondetect.c b/modules/video_filter/motiondetect.c index fb4bf56856..37abd9ce5c 100644 --- a/modules/video_filter/motiondetect.c +++ b/modules/video_filter/motiondetect.c @@ -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", -- 2.39.2