[vlc-devel] commit: Don't duplicate getenv("HOME") ( Rémi Denis-Courmont )

git version control git at videolan.org
Mon May 5 22:40:10 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Mon May  5 22:47:30 2008 +0300| [786f7e30d7e7f328de3ec43ade07c4abb416f2c5]

Don't duplicate getenv("HOME")

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

 src/config/core.c |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/config/core.c b/src/config/core.c
index f5fb904..6d96c85 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -699,29 +699,26 @@ static char *config_GetFooDir (const char *xdg_name, const char *xdg_default)
     free (psz_parent);
     (void)xdg_name; (void)xdg_default;
 #else
-    char var[sizeof ("XDG__HOME") + strlen (xdg_name)], *psz_env;
+    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_env = psz_home ? FromLocaleDup( psz_home ) : NULL;
-    if( psz_env )
+    psz_home = psz_home ? FromLocaleDup( psz_home ) : NULL;
+    if( psz_home )
     {
-        if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 )
+        if( asprintf( &psz_dir, "%s/vlc", psz_home ) == -1 )
             psz_dir = NULL;
         goto out;
     }
 
-    psz_home = getenv( "HOME" );
-    psz_env = psz_home ? FromLocaleDup( psz_home ) : NULL;
-    /* not part of XDG spec but we want a sensible fallback */
-    if( !psz_env )
-        psz_env = config_GetHomeDir();
-    if( asprintf( &psz_dir, "%s/%s/vlc", psz_env, xdg_default ) == -1 )
+    /* 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_env);
+    free (psz_home);
 #endif
     return psz_dir;
 }




More information about the vlc-devel mailing list