Commit 491a0772 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

- mkdir Unicode wrapper (refs #543)

- fix load/save of configuration and creation of configuration directory (refs #528)
parent 52c97a52
......@@ -39,6 +39,7 @@ VLC_EXPORT( void *, utf8_opendir, ( const char *dirname ) );
VLC_EXPORT( const char *, utf8_readdir, ( void *dir ) );
VLC_EXPORT( int, utf8_stat, ( const char *filename, void *buf ) );
VLC_EXPORT( int, utf8_lstat, ( const char *filename, void *buf ) );
VLC_EXPORT( int, utf8_mkdir, ( const char *filename ) );
VLC_EXPORT( char *, EnsureUTF8, ( char * ) );
VLC_EXPORT( char *, FromUTF32, ( const wchar_t * ) );
......
......@@ -208,7 +208,7 @@ VLC_EXPORT( void, config_UnsetCallbacks, ( module_config_t * ) );
#define config_ResetAll(a) __config_ResetAll(VLC_OBJECT(a))
/* internal only */
int config_CreateDir( vlc_object_t *, char * );
int config_CreateDir( vlc_object_t *, const char * );
int config_AutoSaveConfigFile( vlc_object_t * );
/*****************************************************************************
......
......@@ -110,6 +110,7 @@ int __config_LoadCmdLine (vlc_object_t *, int *, char *[], vlc_bool_t);
void __config_PutInt (vlc_object_t *, const char *, int);
vlm_t * __vlm_New (vlc_object_t *);
int __input_Preparse (vlc_object_t *, input_item_t *);
int utf8_mkdir (const char *filename);
int vlc_input_item_AddInfo (input_item_t *p_i, const char *psz_cat, const char *psz_name, const char *psz_format, ...);
void __msg_Unsubscribe (vlc_object_t *, msg_subscription_t *);
void aout_DateSet (audio_date_t *, mtime_t);
......@@ -437,8 +438,8 @@ void __config_ResetAll (vlc_object_t *);
httpd_redirect_t * httpd_RedirectNew (httpd_host_t *, const char *psz_url_dst, const char *psz_url_src);
playlist_item_t * playlist_LockItemGetById (playlist_t *, int);
mtime_t date_Get (const date_t *);
int aout_DecPlay (aout_instance_t *, aout_input_t *, aout_buffer_t *);
int input_vaControl (input_thread_t *, int i_query, va_list);
int aout_DecPlay (aout_instance_t *, aout_input_t *, aout_buffer_t *);
mtime_t aout_FifoFirstDate (aout_instance_t *, aout_fifo_t *);
vout_synchro_t * __vout_SynchroInit (vlc_object_t *, int);
int vlc_alphasort (const struct dirent **a, const struct dirent **b);
......@@ -937,6 +938,7 @@ struct module_symbols_t
int (*utf8_stat_inner) (const char *filename, void *buf);
int (*utf8_lstat_inner) (const char *filename, void *buf);
char * (*FromLocaleDup_inner) (const char *);
int (*utf8_mkdir_inner) (const char *filename);
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
......@@ -1390,6 +1392,7 @@ struct module_symbols_t
# define utf8_stat (p_symbols)->utf8_stat_inner
# define utf8_lstat (p_symbols)->utf8_lstat_inner
# define FromLocaleDup (p_symbols)->FromLocaleDup_inner
# define utf8_mkdir (p_symbols)->utf8_mkdir_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
......@@ -1846,6 +1849,7 @@ struct module_symbols_t
((p_symbols)->utf8_stat_inner) = utf8_stat; \
((p_symbols)->utf8_lstat_inner) = utf8_lstat; \
((p_symbols)->FromLocaleDup_inner) = FromLocaleDup; \
((p_symbols)->utf8_mkdir_inner) = utf8_mkdir; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \
(p_symbols)->__stats_CounterGet_deprecated = NULL; \
(p_symbols)->__stats_TimerDumpAll_deprecated = NULL; \
......
......@@ -790,7 +790,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
/* Acquire config file lock */
vlc_mutex_lock( &p_this->p_vlc->config_lock );
file = fopen( psz_filename, "rt" );
file = utf8_fopen( psz_filename, "rt" );
if( !file )
{
msg_Warn( p_this, "config file %s does not exist yet", psz_filename );
......@@ -951,46 +951,17 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
/*****************************************************************************
* config_CreateDir: Create configuration directory if it doesn't exist.
*****************************************************************************/
int config_CreateDir( vlc_object_t *p_this, char *psz_dirname )
int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname )
{
if( !psz_dirname && !*psz_dirname ) return -1;
#if defined( UNDER_CE )
{
wchar_t psz_new[ MAX_PATH ];
char psz_mod[MAX_PATH];
int i = 0;
/* Convert '/' into '\' */
while( *psz_dirname )
{
if( *psz_dirname == '/' ) psz_mod[i] = '\\';
else psz_mod[i] = *psz_dirname;
psz_dirname++;
i++;
}
psz_mod[i] = 0;
MultiByteToWideChar( CP_ACP, 0, psz_mod, -1, psz_new, MAX_PATH );
if( CreateDirectory( psz_new, NULL ) )
{
msg_Err( p_this, "could not create %s", psz_mod );
}
}
#else
# if defined( WIN32 )
if( mkdir( psz_dirname ) && errno != EEXIST )
# else
if( mkdir( psz_dirname, 0755 ) && errno != EEXIST )
# endif
if( utf8_mkdir( psz_dirname ) && ( errno != EEXIST ) )
{
msg_Err( p_this, "could not create %s (%s)",
psz_dirname, strerror(errno) );
return -1;
}
#endif
return 0;
}
......@@ -1070,7 +1041,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
msg_Dbg( p_this, "opening config file %s", psz_filename );
file = fopen( psz_filename, "rt" );
file = utf8_fopen( psz_filename, "rt" );
if( !file )
{
msg_Warn( p_this, "config file %s does not exist yet", psz_filename );
......@@ -1158,7 +1129,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
* Save module config in file
*/
file = fopen( psz_filename, "wt" );
file = utf8_fopen( psz_filename, "wt" );
if( !file )
{
msg_Warn( p_this, "could not open config file %s for writing",
......
......@@ -308,6 +308,62 @@ FILE *utf8_fopen( const char *filename, const char *mode )
#endif
}
/*****************************************************************************
* utf8_mkdir: Calls mkdir() after conversion of file name to OS locale
*****************************************************************************/
int utf8_mkdir( const char *dirname )
{
#if defined( UNDER_CE ) || defined( WIN32 )
wchar_t wname[MAX_PATH];
char mod[MAX_PATH];
int i;
/* Convert '/' into '\' */
for( i = 0; *dirname; i++ )
{
if( i == MAX_PATH )
return -1; /* overflow */
if( *dirname == '/' )
mod[i] = '\\';
else
mod[i] = *dirname;
dirname++;
}
mod[i] = 0;
if( MultiByteToWideChar( CP_UTF8, 0, mod, -1, wname, MAX_PATH ) == 0 )
{
errno = ENOENT;
return -1;
}
if( CreateDirectoryW( wname, NULL ) == 0 )
{
if( GetLastError( ) == ERROR_ALREADY_EXISTS )
errno = EEXIST;
errno = ENOENT;
return -1;
}
return 0;
#else
char *locname = ToLocale( dirname );
int res;
if( locname == NULL )
{
errno = ENOENT;
return -1;
}
res = mkdir( locname, 0755 );
LocaleFree( locname );
return res;
#endif
}
void *utf8_opendir( const char *dirname )
{
const char *local_name = ToLocale( dirname );
......
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