]> git.sesse.net Git - vlc/commitdiff
Make config_GetHomeDir return a const string too
authorRémi Denis-Courmont <rem@videolan.org>
Thu, 22 May 2008 17:32:25 +0000 (20:32 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Thu, 22 May 2008 18:29:04 +0000 (21:29 +0300)
include/vlc_main.h
src/config/configuration.h
src/config/dirs.c
src/libvlc-common.c

index 2168788368a5f57418be705b39b85c250cd488dc..58dcc8e043cedc41887517b0cf8106f7978658c4 100644 (file)
@@ -37,7 +37,7 @@ struct libvlc_int_t
     VLC_COMMON_MEMBERS
 
     /* Global properties */
-    char *                 psz_homedir;      ///< user's home directory
+    const char *          psz_homedir;      ///< user's home directory
 
     global_stats_t       *p_stats;           ///< Global statistics
 
index a26bd27cc4935d465e0c3d2711a3131d58f9e821..bd7ae607ffa208357986a780fad9572389db8545 100644 (file)
@@ -43,7 +43,7 @@ void config_UnsetCallbacks( module_config_t *, size_t );
 #define config_LoadConfigFile(a,b) __config_LoadConfigFile(VLC_OBJECT(a),b)
 
 int __config_LoadCmdLine   ( vlc_object_t *, int *, const char *[], bool );
-char *config_GetHomeDir    ( void );
+const char *config_GetHomeDir ( void );
 char *config_GetCustomConfigFile( libvlc_int_t * );
 int __config_LoadConfigFile( vlc_object_t *, const char * );
 
index de1a1c748f8b6b357ace82fdb51b0e31878cc326..00d949ad18a5608022c48b9677941a2b9b99dd89 100644 (file)
@@ -92,6 +92,7 @@ const char *config_GetConfDir( void )
 
 static const char *GetDir( bool b_appdata )
 {
+    /* FIXME: a full memory page here - quite a waste... */
     static char homedir[PATH_MAX] = "";
 
 #if defined (WIN32)
@@ -153,43 +154,40 @@ static const char *GetDir( bool b_appdata )
 /**
  * Get the user's home directory
  */
-char *config_GetHomeDir( void )
+const char *config_GetHomeDir( void )
 {
-    return strdup (GetDir( false ));
+    return GetDir (false);
 }
 
 static char *config_GetFooDir (const char *xdg_name, const char *xdg_default)
 {
     char *psz_dir;
 #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS)
-    char *psz_parent = strdup (GetDir (true));
+    const char *psz_parent = GetDir (true);
 
     if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 )
         psz_dir = NULL;
 
-    free (psz_parent);
     (void)xdg_name; (void)xdg_default;
 #else
     char var[sizeof ("XDG__HOME") + strlen (xdg_name)];
-
     /* XDG Base Directory Specification - Version 0.6 */
     snprintf (var, sizeof (var), "XDG_%s_HOME", xdg_name);
-    char *psz_home = getenv( var );
-    psz_home = psz_home ? FromLocaleDup( psz_home ) : NULL;
+
+    const char *psz_home = getenv (var);
+    psz_home = psz_home ? FromLocale (psz_home) : NULL;
     if( psz_home )
     {
         if( asprintf( &psz_dir, "%s/vlc", psz_home ) == -1 )
             psz_dir = NULL;
-        goto out;
+        LocaleFree (psz_home);
+        return psz_dir;
     }
 
     /* Try HOME, then fallback to non-XDG dirs */
     psz_home = config_GetHomeDir();
     if( asprintf( &psz_dir, "%s/%s/vlc", psz_home, xdg_default ) == -1 )
         psz_dir = NULL;
-
-out:
-    free (psz_home);
 #endif
     return psz_dir;
 }
index 2efc6c80d83e7c943c3ee5c77e00ec4658b2c923..2811eb7b9e588083c3d8e02228f52409de9d0484 100644 (file)
@@ -1065,7 +1065,6 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release )
     /* Free module bank. It is refcounted, so we call this each time  */
     module_EndBank( p_libvlc );
 
-    FREENULL( p_libvlc->psz_homedir );
     FREENULL( priv->psz_configfile );
     var_DelCallback( p_libvlc, "key-pressed", vlc_key_to_action,
                      p_libvlc->p_hotkeys );