[vlc-devel] commit: Make config_GetHomeDir return a const string too ( Rémi Denis-Courmont )

git version control git at videolan.org
Thu May 22 20:27:34 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Thu May 22 20:32:25 2008 +0300| [46c39c8e9c2e0ec3ba1bf8dc37e6e3e5efb59a08]

Make config_GetHomeDir return a const string too

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=46c39c8e9c2e0ec3ba1bf8dc37e6e3e5efb59a08
---

 include/vlc_main.h         |    2 +-
 src/config/configuration.h |    2 +-
 src/config/dirs.c          |   20 +++++++++-----------
 src/libvlc-common.c        |    1 -
 4 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/include/vlc_main.h b/include/vlc_main.h
index 2168788..58dcc8e 100644
--- a/include/vlc_main.h
+++ b/include/vlc_main.h
@@ -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
 
diff --git a/src/config/configuration.h b/src/config/configuration.h
index a26bd27..bd7ae60 100644
--- a/src/config/configuration.h
+++ b/src/config/configuration.h
@@ -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 * );
 
diff --git a/src/config/dirs.c b/src/config/dirs.c
index de1a1c7..00d949a 100644
--- a/src/config/dirs.c
+++ b/src/config/dirs.c
@@ -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;
 }
diff --git a/src/libvlc-common.c b/src/libvlc-common.c
index 2efc6c8..2811eb7 100644
--- a/src/libvlc-common.c
+++ b/src/libvlc-common.c
@@ -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 );




More information about the vlc-devel mailing list