X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fconfig%2Ffile.c;h=894ebbb14e081062cd69a7f446e5881b0612b9a4;hb=688f0a8d8913f20ac5d3e27bf4f2bbe35c9f5de7;hp=7b1467a01fdb9828ddd7e7775255dfc12fc8adfc;hpb=df61d33b06e2b3cbbe746b2f5a9bea5b370c24ff;p=vlc diff --git a/src/config/file.c b/src/config/file.c index 7b1467a01f..894ebbb14e 100644 --- a/src/config/file.c +++ b/src/config/file.c @@ -25,7 +25,7 @@ # include "config.h" #endif -#include +#include #include "../libvlc.h" #include "vlc_charset.h" #include "vlc_keys.h" @@ -33,6 +33,11 @@ #include /* errno */ #include #include +#ifdef __APPLE__ +# include +#else +#include +#endif #include "configuration.h" #include "modules/modules.h" @@ -44,14 +49,28 @@ static inline char *strdupnull (const char *src) return src ? strdup (src) : NULL; } +/** + * Get the user's configuration file + */ +static char *config_GetConfigFile( void ) +{ + char *psz_dir = config_GetUserConfDir(); + char *psz_configfile; + + if( asprintf( &psz_configfile, "%s" DIR_SEP CONFIG_FILE, psz_dir ) == -1 ) + psz_configfile = NULL; + free( psz_dir ); + return psz_configfile; +} + static FILE *config_OpenConfigFile( vlc_object_t *p_obj, const char *mode ) { - char *psz_filename = p_obj->p_libvlc->psz_configfile; + char *psz_filename = libvlc_priv (p_obj->p_libvlc)->psz_configfile; FILE *p_stream; if( !psz_filename ) { - psz_filename = config_GetConfigFile( p_obj->p_libvlc ); + psz_filename = config_GetConfigFile(); } msg_Dbg( p_obj, "opening config file (%s)", psz_filename ); @@ -70,7 +89,7 @@ static FILE *config_OpenConfigFile( vlc_object_t *p_obj, const char *mode ) * Specification configs */ char *psz_old; if( asprintf( &psz_old, "%s" DIR_SEP CONFIG_DIR DIR_SEP CONFIG_FILE, - p_obj->p_libvlc->psz_homedir ) != -1 ) + config_GetHomeDir() ) != -1 ) { p_stream = utf8_fopen( psz_old, mode ); if( p_stream ) @@ -81,19 +100,18 @@ static FILE *config_OpenConfigFile( vlc_object_t *p_obj, const char *mode ) "VLC will now use %s.", psz_old, psz_filename ); char *psz_readme; if( asprintf(&psz_readme,"%s"DIR_SEP CONFIG_DIR DIR_SEP"README", - p_obj->p_libvlc->psz_homedir ) != -1 ) + config_GetHomeDir() ) != -1 ) { FILE *p_readme = utf8_fopen( psz_readme, "wt" ); if( p_readme ) { - fputs( "The VLC media player configuration folder has " - "moved to comply with the XDG Base " - "Directory Specification version 0.6. Your " - "configuration has been copied to the new " - "location (", p_readme ); - fputs( p_obj->p_libvlc->psz_configdir, p_readme ); - fputs( "). You can delete this directory and " - "all its contents.", p_readme ); + fprintf( p_readme, "The VLC media player " + "configuration folder has moved to comply\n" + "with the XDG Base Directory Specification " + "version 0.6. Your\nconfiguration has been " + "copied to the new location:\n%s\nYou can " + "delete this directory and all its contents.", + psz_filename); fclose( p_readme ); } free( psz_readme ); @@ -105,7 +123,7 @@ static FILE *config_OpenConfigFile( vlc_object_t *p_obj, const char *mode ) #endif else if( p_stream != NULL ) { - p_obj->p_libvlc->psz_configfile = psz_filename; + libvlc_priv (p_obj->p_libvlc)->psz_configfile = psz_filename; } return p_stream; @@ -139,6 +157,7 @@ static int strtoi (const char *str) *****************************************************************************/ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) { + libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); vlc_list_t *p_list; FILE *file; @@ -147,7 +166,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) return VLC_EGENERIC; /* Acquire config file lock */ - vlc_mutex_lock( &p_this->p_libvlc->config_lock ); + vlc_mutex_lock( &priv->config_lock ); /* Look for the selected module, if NULL then save everything */ p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); @@ -167,6 +186,10 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) char line[1024], section[1022]; section[0] = '\0'; + /* Ensure consistent number formatting... */ + locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL); + locale_t baseloc = uselocale (loc); + while (fgets (line, 1024, file) != NULL) { /* Ignore comments and empty lines */ @@ -258,7 +281,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) case CONFIG_ITEM_FLOAT: if( !*psz_option_value ) break; /* ignore empty option */ - p_item->value.f = (float)i18n_atof( psz_option_value); + p_item->value.f = (float)atof (psz_option_value); p_item->saved.f = p_item->value.f; break; @@ -295,8 +318,13 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) fclose (file); vlc_list_release( p_list ); + if (loc != (locale_t)0) + { + uselocale (baseloc); + freelocale (loc); + } - vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); + vlc_mutex_unlock( &priv->config_lock ); return 0; } @@ -305,7 +333,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) *****************************************************************************/ int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname ) { - if( !psz_dirname && !*psz_dirname ) return -1; + if( !psz_dirname || !*psz_dirname ) return -1; if( utf8_mkdir( psz_dirname, 0700 ) == 0 ) return 0; @@ -386,6 +414,7 @@ config_Write (FILE *file, const char *type, const char *desc, static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, bool b_autosave ) { + libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); module_t *p_parser; vlc_list_t *p_list; FILE *file; @@ -396,19 +425,20 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, int i_index; /* Acquire config file lock */ - vlc_mutex_lock( &p_this->p_libvlc->config_lock ); + vlc_mutex_lock( &priv->config_lock ); - if( p_this->p_libvlc->psz_configfile == NULL ) + if( libvlc_priv (p_this->p_libvlc)->psz_configfile == NULL ) { - const char *psz_configdir = p_this->p_libvlc->psz_configdir; + char *psz_configdir = config_GetUserConfDir(); if( !psz_configdir ) /* XXX: This should never happen */ { msg_Err( p_this, "no configuration directory defined" ); - vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); + vlc_mutex_unlock( &priv->config_lock ); return -1; } config_CreateDir( p_this, psz_configdir ); + free( psz_configdir ); } file = config_OpenConfigFile( p_this, "rt" ); @@ -424,7 +454,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, if( !p_bigbuffer ) { if( file ) fclose( file ); - vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); + vlc_mutex_unlock( &priv->config_lock ); return -1; } p_bigbuffer[0] = 0; @@ -498,13 +528,17 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, { vlc_list_release( p_list ); free( p_bigbuffer ); - vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); + vlc_mutex_unlock( &priv->config_lock ); return -1; } fprintf( file, "\xEF\xBB\xBF###\n### " COPYRIGHT_MESSAGE "\n###\n\n" "###\n### lines beginning with a '#' character are comments\n###\n\n" ); + /* Ensure consistent number formatting... */ + locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL); + locale_t baseloc = uselocale (loc); + /* Look for the selected module, if NULL then save everything */ for( i_index = 0; i_index < p_list->i_count; i_index++ ) { @@ -611,6 +645,11 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, } vlc_list_release( p_list ); + if (loc != (locale_t)0) + { + uselocale (baseloc); + freelocale (loc); + } /* * Restore old settings from the config in file @@ -619,20 +658,21 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, free( p_bigbuffer ); fclose( file ); - vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); + vlc_mutex_unlock( &priv->config_lock ); return 0; } int config_AutoSaveConfigFile( vlc_object_t *p_this ) { + libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); vlc_list_t *p_list; int i_index, i_count; assert( p_this ); /* Check if there's anything to save */ - vlc_mutex_lock( &p_this->p_libvlc->config_lock ); + vlc_mutex_lock( &priv->config_lock ); p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); i_count = p_list->i_count; for( i_index = 0; i_index < i_count; i_index++ ) @@ -651,7 +691,7 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this ) if( p_item < p_end ) break; } vlc_list_release( p_list ); - vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); + vlc_mutex_unlock( &priv->config_lock ); if( i_index == i_count ) return VLC_SUCCESS; return SaveConfigFile( p_this, 0, true ); @@ -662,18 +702,6 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name ) return SaveConfigFile( p_this, psz_module_name, false ); } -/** - * Get the user's configuration file - */ -char *config_GetConfigFile( libvlc_int_t *p_libvlc ) -{ - char *psz_configfile; - if( asprintf( &psz_configfile, "%s" DIR_SEP CONFIG_FILE, - p_libvlc->psz_configdir ) == -1 ) - return NULL; - return psz_configfile; -} - /** * Get the user's configuration file when given with the --config option */ @@ -686,7 +714,7 @@ char *config_GetCustomConfigFile( libvlc_int_t *p_libvlc ) { /* This is incomplete: we should also support the ~cmassiot/ syntax */ char *psz_buf; - if( asprintf( &psz_buf, "%s/%s", p_libvlc->psz_homedir, + if( asprintf( &psz_buf, "%s/%s", config_GetHomeDir(), psz_configfile + 2 ) == -1 ) { free( psz_configfile );