X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fconfiguration.c;h=efe5049d2be2121fd981ef54d27978a95c78d2f3;hb=28a1f4c6267a8d4d8f130f367712710a694e6db1;hp=e0a09112f849785d3f34ade59ccf94b9787a0bc9;hpb=85b29bdc288a1573d43bd524908be5748a9b3640;p=vlc diff --git a/src/misc/configuration.c b/src/misc/configuration.c index e0a09112f8..efe5049d2b 100644 --- a/src/misc/configuration.c +++ b/src/misc/configuration.c @@ -1,7 +1,7 @@ /***************************************************************************** * configuration.c management of the modules configuration ***************************************************************************** - * Copyright (C) 2001-2004 VideoLAN (Centrale Réseaux) and its contributors + * Copyright (C) 2001-2004 the VideoLAN team * $Id$ * * Authors: Gildas Bazin @@ -18,17 +18,22 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ #include #include "vlc_keys.h" +#include "charset.h" #include /* sprintf() */ #include /* free(), strtol() */ #include /* strdup() */ #include /* errno */ +#ifdef HAVE_LIMITS_H +# include +#endif + #ifdef HAVE_UNISTD_H # include /* getuid() */ #endif @@ -58,7 +63,6 @@ #include #endif - static int ConfigStringToKey( char * ); static char *ConfigKeyToString( int ); @@ -716,7 +720,7 @@ void __config_ResetAll( vlc_object_t *p_this ) module_t *p_module; /* Acquire config file lock */ - vlc_mutex_lock( &p_this->p_vlc->config_lock ); + vlc_mutex_lock( &p_this->p_libvlc->config_lock ); p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); @@ -738,7 +742,7 @@ void __config_ResetAll( vlc_object_t *p_this ) } vlc_list_release( p_list ); - vlc_mutex_unlock( &p_this->p_vlc->config_lock ); + vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); } /***************************************************************************** @@ -758,10 +762,10 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) char *psz_filename, *psz_homedir, *psz_configfile; int i_index; - psz_configfile = p_this->p_vlc->psz_configfile; + psz_configfile = p_this->p_libvlc->psz_configfile; if( !psz_configfile || !psz_configfile ) { - psz_homedir = p_this->p_vlc->psz_homedir; + psz_homedir = p_this->p_libvlc->psz_homedir; if( !psz_homedir ) { msg_Err( p_this, "psz_homedir is null" ); @@ -770,7 +774,8 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) psz_filename = (char *)malloc( sizeof("/" CONFIG_DIR "/" CONFIG_FILE) + strlen(psz_homedir) ); if( psz_filename ) - sprintf( psz_filename, "%s/" CONFIG_DIR "/" CONFIG_FILE, + sprintf( psz_filename, + "%s" DIR_SEP CONFIG_DIR DIR_SEP CONFIG_FILE, psz_homedir ); } else @@ -787,14 +792,14 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) msg_Dbg( p_this, "opening config file %s", psz_filename ); /* Acquire config file lock */ - vlc_mutex_lock( &p_this->p_vlc->config_lock ); + vlc_mutex_lock( &p_this->p_libvlc->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 ); free( psz_filename ); - vlc_mutex_unlock( &p_this->p_vlc->config_lock ); + vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); return -1; } @@ -889,7 +894,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->f_value = (float)atof( psz_option_value); + p_item->f_value = (float)i18n_atof( psz_option_value); p_item->f_value_saved = p_item->f_value; #if 0 msg_Dbg( p_this, "option \"%s\", value %f", @@ -942,7 +947,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) fclose( file ); free( psz_filename ); - vlc_mutex_unlock( &p_this->p_vlc->config_lock ); + vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); return 0; } @@ -950,46 +955,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; } @@ -1012,8 +988,8 @@ int config_CreateDir( vlc_object_t *p_this, char *psz_dirname ) * save. * Really stupid no ? *****************************************************************************/ -int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, - vlc_bool_t b_autosave ) +static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, + vlc_bool_t b_autosave ) { module_t *p_parser; vlc_list_t *p_list; @@ -1027,34 +1003,34 @@ 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_vlc->config_lock ); + vlc_mutex_lock( &p_this->p_libvlc->config_lock ); - psz_configfile = p_this->p_vlc->psz_configfile; + psz_configfile = p_this->p_libvlc->psz_configfile; if( !psz_configfile || !psz_configfile ) { - psz_homedir = p_this->p_vlc->psz_homedir; + psz_homedir = p_this->p_libvlc->psz_homedir; if( !psz_homedir ) { msg_Err( p_this, "psz_homedir is null" ); - vlc_mutex_unlock( &p_this->p_vlc->config_lock ); + vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); return -1; } psz_filename = (char *)malloc( sizeof("/" CONFIG_DIR "/" CONFIG_FILE) + strlen(psz_homedir) ); if( psz_filename ) - sprintf( psz_filename, "%s/" CONFIG_DIR, psz_homedir ); + sprintf( psz_filename, "%s" DIR_SEP CONFIG_DIR, psz_homedir ); if( !psz_filename ) { msg_Err( p_this, "out of memory" ); - vlc_mutex_unlock( &p_this->p_vlc->config_lock ); + vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); return -1; } config_CreateDir( p_this, psz_filename ); - strcat( psz_filename, "/" CONFIG_FILE ); + strcat( psz_filename, DIR_SEP CONFIG_FILE ); } else { @@ -1062,14 +1038,14 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, if( !psz_filename ) { msg_Err( p_this, "out of memory" ); - vlc_mutex_unlock( &p_this->p_vlc->config_lock ); + vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); return -1; } } 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 ); @@ -1088,7 +1064,7 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, msg_Err( p_this, "out of memory" ); if( file ) fclose( file ); free( psz_filename ); - vlc_mutex_unlock( &p_this->p_vlc->config_lock ); + vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); return -1; } p_bigbuffer[0] = 0; @@ -1157,18 +1133,19 @@ 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", psz_filename ); free( psz_filename ); vlc_list_release( p_list ); - vlc_mutex_unlock( &p_this->p_vlc->config_lock ); + vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); return -1; } - fprintf( file, "###\n### " COPYRIGHT_MESSAGE "\n###\n\n" ); + fprintf( file, "###\n### " COPYRIGHT_MESSAGE "\n###\n\n" + "###\n### lines begining with a '#' character are comments\n###\n\n" ); /* Look for the selected module, if NULL then save everything */ for( i_index = 0; i_index < p_list->i_count; i_index++ ) @@ -1188,7 +1165,7 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, fprintf( file, "[%s]", p_parser->psz_object_name ); if( p_parser->psz_longname ) - fprintf( file, " # %s\n\n", p_parser->psz_longname ); + utf8_fprintf( file, " # %s\n\n", p_parser->psz_longname ); else fprintf( file, "\n\n" ); @@ -1224,7 +1201,7 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, case CONFIG_ITEM_BOOL: case CONFIG_ITEM_INTEGER: if( p_item->psz_text ) - fprintf( file, "# %s (%s)\n", p_item->psz_text, + utf8_fprintf( file, "# %s (%s)\n", p_item->psz_text, (p_item->i_type == CONFIG_ITEM_BOOL) ? _("boolean") : _("integer") ); if( i_value == p_item->i_value_orig ) @@ -1236,7 +1213,7 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, case CONFIG_ITEM_KEY: if( p_item->psz_text ) - fprintf( file, "# %s (%s)\n", p_item->psz_text, + utf8_fprintf( file, "# %s (%s)\n", p_item->psz_text, _("key") ); if( i_value == p_item->i_value_orig ) fprintf( file, "#" ); @@ -1250,7 +1227,7 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, case CONFIG_ITEM_FLOAT: if( p_item->psz_text ) - fprintf( file, "# %s (%s)\n", p_item->psz_text, + utf8_fprintf( file, "# %s (%s)\n", p_item->psz_text, _("float") ); if( f_value == p_item->f_value_orig ) fprintf( file, "#" ); @@ -1261,7 +1238,7 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, default: if( p_item->psz_text ) - fprintf( file, "# %s (%s)\n", p_item->psz_text, + utf8_fprintf( file, "# %s (%s)\n", p_item->psz_text, _("string") ); if( (!psz_value && !p_item->psz_value_orig) || (psz_value && p_item->psz_value_orig && @@ -1294,7 +1271,7 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, fclose( file ); free( psz_filename ); - vlc_mutex_unlock( &p_this->p_vlc->config_lock ); + vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); return 0; } @@ -1307,7 +1284,7 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this ) int i_index, i_count; /* Check if there's anything to save */ - vlc_mutex_lock( &p_this->p_vlc->config_lock ); + vlc_mutex_lock( &p_this->p_libvlc->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++ ) @@ -1325,7 +1302,7 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this ) if( p_item->i_type != CONFIG_HINT_END ) break; } vlc_list_release( p_list ); - vlc_mutex_unlock( &p_this->p_vlc->config_lock ); + vlc_mutex_unlock( &p_this->p_libvlc->config_lock ); if( i_index == i_count ) return VLC_SUCCESS; return SaveConfigFile( p_this, 0, VLC_TRUE ); @@ -1360,11 +1337,11 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], char *psz_shortopts; /* Set default configuration and copy arguments */ - p_this->p_vlc->i_argc = *pi_argc; - p_this->p_vlc->ppsz_argv = ppsz_argv; + p_this->p_libvlc->i_argc = *pi_argc; + p_this->p_libvlc->ppsz_argv = ppsz_argv; -#ifdef SYS_DARWIN - /* When vlc.app is run by double clicking in Mac OS X, the 2nd arg +#ifdef __APPLE__ + /* When VLC.app is run by double clicking in Mac OS X, the 2nd arg * is the PSN - process serial number (a unique PID-ish thingie) * still ok for real Darwin & when run from command line */ if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) ) @@ -1397,7 +1374,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ; /* count the number of exported configuration options (to allocate - * longopts). We also need to allocate space for too options when + * longopts). We also need to allocate space for two options when * dealing with boolean to allow for --foo and --no-foo */ i_opts += p_parser->i_config_items + 2 * p_parser->i_bool_items; @@ -1434,7 +1411,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], vlc_list_release( p_list ); return -1; } - memcpy( ppsz_argv, p_this->p_vlc->ppsz_argv, + memcpy( ppsz_argv, p_this->p_libvlc->ppsz_argv, *pi_argc * sizeof(char *) ); } @@ -1553,7 +1530,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], { if( !strcmp(p_conf->psz_current,"SUPPRESSED") ) { - if( !b_ignore_errors ) + if( !b_ignore_errors ) { fprintf(stderr, "Warning: option --%s is no longer used.\n", @@ -1586,83 +1563,83 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], p_conf = config_FindConfig( p_this, psz_name ); } - switch( p_conf->i_type ) + switch( p_conf->i_type ) + { + case CONFIG_ITEM_STRING: + case CONFIG_ITEM_FILE: + case CONFIG_ITEM_DIRECTORY: + case CONFIG_ITEM_MODULE: + case CONFIG_ITEM_MODULE_LIST: + case CONFIG_ITEM_MODULE_LIST_CAT: + case CONFIG_ITEM_MODULE_CAT: + config_PutPsz( p_this, psz_name, optarg ); + break; + case CONFIG_ITEM_INTEGER: + config_PutInt( p_this, psz_name, strtol(optarg, 0, 0)); + break; + case CONFIG_ITEM_FLOAT: + config_PutFloat( p_this, psz_name, (float)atof(optarg) ); + break; + case CONFIG_ITEM_KEY: + config_PutInt( p_this, psz_name, ConfigStringToKey( optarg ) ); + break; + case CONFIG_ITEM_BOOL: + config_PutInt( p_this, psz_name, !flag ); + break; + } + continue; + } + } + + /* A short option has been recognized */ + if( pp_shortopts[i_cmd] != NULL ) + { + switch( pp_shortopts[i_cmd]->i_type ) { case CONFIG_ITEM_STRING: case CONFIG_ITEM_FILE: case CONFIG_ITEM_DIRECTORY: case CONFIG_ITEM_MODULE: + case CONFIG_ITEM_MODULE_CAT: case CONFIG_ITEM_MODULE_LIST: case CONFIG_ITEM_MODULE_LIST_CAT: - case CONFIG_ITEM_MODULE_CAT: - config_PutPsz( p_this, psz_name, optarg ); + config_PutPsz( p_this, pp_shortopts[i_cmd]->psz_name, optarg ); break; case CONFIG_ITEM_INTEGER: - config_PutInt( p_this, psz_name, strtol(optarg, 0, 0)); - break; - case CONFIG_ITEM_FLOAT: - config_PutFloat( p_this, psz_name, (float)atof(optarg) ); - break; - case CONFIG_ITEM_KEY: - config_PutInt( p_this, psz_name, ConfigStringToKey( optarg ) ); - break; - case CONFIG_ITEM_BOOL: - config_PutInt( p_this, psz_name, !flag ); - break; - } - - continue; - } - } - /* A short option has been recognized */ - if( pp_shortopts[i_cmd] != NULL ) - { - switch( pp_shortopts[i_cmd]->i_type ) - { - case CONFIG_ITEM_STRING: - case CONFIG_ITEM_FILE: - case CONFIG_ITEM_DIRECTORY: - case CONFIG_ITEM_MODULE: - case CONFIG_ITEM_MODULE_CAT: - case CONFIG_ITEM_MODULE_LIST: - case CONFIG_ITEM_MODULE_LIST_CAT: - config_PutPsz( p_this, pp_shortopts[i_cmd]->psz_name, optarg ); - break; - case CONFIG_ITEM_INTEGER: - if( i_cmd == 'v' ) - { - if( optarg ) + if( i_cmd == 'v' ) { - if( *optarg == 'v' ) /* eg. -vvv */ + if( optarg ) { - i_verbose++; - while( *optarg == 'v' ) + if( *optarg == 'v' ) /* eg. -vvv */ { i_verbose++; - optarg++; + while( *optarg == 'v' ) + { + i_verbose++; + optarg++; + } + } + else + { + i_verbose += atoi( optarg ); /* eg. -v2 */ } } else { - i_verbose += atoi( optarg ); /* eg. -v2 */ + i_verbose++; /* -v */ } + config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name, + i_verbose ); } else { - i_verbose++; /* -v */ + config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name, + strtol(optarg, 0, 0) ); } - config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name, - i_verbose ); - } - else - { - config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name, - strtol(optarg, 0, 0) ); - } - break; - case CONFIG_ITEM_BOOL: - config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name, 1 ); - break; + break; + case CONFIG_ITEM_BOOL: + config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name, 1 ); + break; } continue; @@ -1673,7 +1650,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], { fprintf( stderr, "%s: unknown option" " or missing mandatory argument ", - p_this->p_vlc->psz_object_name ); + p_this->p_libvlc->psz_object_name ); if( optopt ) { fprintf( stderr, "`-%c'\n", optopt ); @@ -1683,7 +1660,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], fprintf( stderr, "`%s'\n", ppsz_argv[optind-1] ); } fprintf( stderr, "Try `%s --help' for more information.\n", - p_this->p_vlc->psz_object_name ); + p_this->p_libvlc->psz_object_name ); for( i_index = 0; p_longopts[i_index].name; i_index++ ) free( (char *)p_longopts[i_index].name ); @@ -1703,16 +1680,40 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], return 0; } +/** + * config_GetDataDir: find directory where shared data is installed + * + * @return a string (always succeeds). + */ +const char *config_GetDataDir( const vlc_object_t *p_this ) +{ +#if defined (WIN32) || defined (UNDER_CE) + return p_this->p_libvlc_global->psz_vlcpath; +#elif defined(__APPLE__) || defined (SYS_BEOS) + static char path[PATH_MAX] = ""; + + if( *path == '\0' ) + { + snprintf( path, sizeof( path ), "%s/share", + p_this->p_libvlc_global->psz_vlcpath ); + path[sizeof( path ) - 1] = '\0'; + } + return path; +#else + return DATA_PATH; +#endif +} + /***************************************************************************** - * config_GetHomeDir: find the user's home directory. + * config_GetHomeDir, config_GetUserDir: find the user's home directory. ***************************************************************************** * This function will try by different ways to find the user's home path. * Note that this function is not reentrant, it should be called only once * at the beginning of main where the result will be stored for later use. *****************************************************************************/ -char *config_GetHomeDir( void ) +static char *GetDir( vlc_bool_t b_appdata ) { - char *p_tmp, *p_homedir = NULL; + const char *psz_localhome = NULL; #if defined(HAVE_GETPWUID) struct passwd *p_pw = NULL; @@ -1720,13 +1721,16 @@ char *config_GetHomeDir( void ) #if defined(WIN32) && !defined(UNDER_CE) typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD, - LPSTR ); + LPWSTR ); #ifndef CSIDL_FLAG_CREATE # define CSIDL_FLAG_CREATE 0x8000 #endif #ifndef CSIDL_APPDATA # define CSIDL_APPDATA 0x1A #endif +#ifndef CSIDL_PROFILE +# define CSIDL_PROFILE 0x28 +#endif #ifndef SHGFP_TYPE_CURRENT # define SHGFP_TYPE_CURRENT 0 #endif @@ -1738,23 +1742,21 @@ char *config_GetHomeDir( void ) if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL ) { SHGetFolderPath = (void *)GetProcAddress( shfolder_dll, - _T("SHGetFolderPathA") ); + _T("SHGetFolderPathW") ); if ( SHGetFolderPath != NULL ) { - p_homedir = (char *)malloc( MAX_PATH ); - if( !p_homedir ) return NULL; + wchar_t whomedir[MAX_PATH]; /* get the "Application Data" folder for the current user */ if( S_OK == SHGetFolderPath( NULL, - CSIDL_APPDATA | CSIDL_FLAG_CREATE, + (b_appdata ? CSIDL_APPDATA : + CSIDL_PROFILE) | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, - p_homedir ) ) + whomedir ) ) { FreeLibrary( shfolder_dll ); - return p_homedir; + return FromWide( whomedir ); } - free( p_homedir ); - p_homedir = NULL; } FreeLibrary( shfolder_dll ); } @@ -1765,41 +1767,41 @@ char *config_GetHomeDir( void ) # define CSIDL_APPDATA 0x1A #endif - wchar_t p_whomedir[MAX_PATH]; + wchar_t whomedir[MAX_PATH]; /* get the "Application Data" folder for the current user */ - if( SHGetSpecialFolderPath( NULL, p_whomedir, CSIDL_APPDATA, 1 ) ) - { - p_homedir = (char *)malloc( MAX_PATH ); - if( !p_homedir ) return NULL; - - sprintf( p_homedir, "%ls", p_whomedir ); - return p_homedir; - } + if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) ) + return FromWide( whomedir ); #endif #if defined(HAVE_GETPWUID) if( ( p_pw = getpwuid( getuid() ) ) == NULL ) #endif { - if( ( p_tmp = getenv( "HOME" ) ) == NULL ) + psz_localhome = getenv( "HOME" ); + if( psz_localhome == NULL ) { - if( ( p_tmp = getenv( "TMP" ) ) == NULL ) - { - p_tmp = "/tmp"; - } + psz_localhome = getenv( "TMP" ); + if( psz_localhome == NULL ) + psz_localhome = "/tmp"; } - - p_homedir = strdup( p_tmp ); } #if defined(HAVE_GETPWUID) else - { - p_homedir = strdup( p_pw->pw_dir ); - } + psz_localhome = p_pw->pw_dir; #endif - return p_homedir; + return FromLocaleDup( psz_localhome ); +} + +char *config_GetHomeDir( void ) +{ + return GetDir( VLC_TRUE ); +} + +char *config_GetUserDir( void ) +{ + return GetDir( VLC_FALSE ); }