Commit 786f7e30 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Don't duplicate getenv("HOME")

parent d73e233d
...@@ -699,29 +699,26 @@ static char *config_GetFooDir (const char *xdg_name, const char *xdg_default) ...@@ -699,29 +699,26 @@ static char *config_GetFooDir (const char *xdg_name, const char *xdg_default)
free (psz_parent); free (psz_parent);
(void)xdg_name; (void)xdg_default; (void)xdg_name; (void)xdg_default;
#else #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 */ /* XDG Base Directory Specification - Version 0.6 */
snprintf (var, sizeof (var), "XDG_%s_HOME", xdg_name); snprintf (var, sizeof (var), "XDG_%s_HOME", xdg_name);
char *psz_home = getenv( var ); char *psz_home = getenv( var );
psz_env = psz_home ? FromLocaleDup( psz_home ) : NULL; psz_home = psz_home ? FromLocaleDup( psz_home ) : NULL;
if( psz_env ) if( psz_home )
{ {
if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 ) if( asprintf( &psz_dir, "%s/vlc", psz_home ) == -1 )
psz_dir = NULL; psz_dir = NULL;
goto out; goto out;
} }
psz_home = getenv( "HOME" ); /* Try HOME, then fallback to non-XDG dirs */
psz_env = psz_home ? FromLocaleDup( psz_home ) : NULL; psz_home = config_GetHomeDir();
/* not part of XDG spec but we want a sensible fallback */ if( asprintf( &psz_dir, "%s/%s/vlc", psz_home, xdg_default ) == -1 )
if( !psz_env )
psz_env = config_GetHomeDir();
if( asprintf( &psz_dir, "%s/%s/vlc", psz_env, xdg_default ) == -1 )
psz_dir = NULL; psz_dir = NULL;
out: out:
free (psz_env); free (psz_home);
#endif #endif
return psz_dir; return psz_dir;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment