Changeset 09b452a36de6130d12d598f1159816b8bbe960b5

Show
Ignore:
Timestamp:
04/05/08 21:00:51 (5 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1209927651 +0300
git-parent:

[60987ce27f1f6931311cf1bbf7dcc5d704b96a2f]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1209927651 +0300
Message:

XDG code factorization

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/config/core.c

    r9df2848 r09b452a  
    725725} 
    726726 
     727static char *config_GetFooDir (libvlc_int_t *p_libvlc, const char *xdg_name, 
     728                               const char *xdg_default) 
     729{ 
     730    char *psz_dir; 
     731#if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS) 
     732    char *psz_parent = config_GetUserDir(); 
     733 
     734    if( !psz_parent ) 
     735        psz_parent = p_libvlc->psz_homedir; 
     736    if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 ) 
     737        psz_dir = NULL; 
     738 
     739    (void)xdg_name; (void)xdg_default; 
     740    return psz_dir; 
     741#else 
     742    char var[sizeof ("XDG__HOME") + strlen (xdg_name)], *psz_env; 
     743 
     744    /* XDG Base Directory Specification - Version 0.6 */ 
     745    snprintf (var, sizeof (var), "XDG_%s_HOME", xdg_name); 
     746    psz_env = getenv (var); 
     747    if( psz_env ) 
     748    { 
     749        if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 ) 
     750            return NULL; 
     751        return psz_dir; 
     752    } 
     753 
     754    psz_env = getenv( "HOME" ); 
     755    /* not part of XDG spec but we want a sensible fallback */ 
     756    if( !psz_env ) 
     757        psz_env = p_libvlc->psz_homedir; 
     758    if( asprintf( &psz_dir, "%s/%s/vlc", psz_env, xdg_default ) == -1 ) 
     759        return NULL; 
     760    return psz_dir; 
     761#endif 
     762} 
     763 
    727764/** 
    728765 * Get the user's VLC configuration directory 
     
    730767char *config_GetConfigDir( libvlc_int_t *p_libvlc ) 
    731768{ 
    732     char *psz_dir; 
    733 #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS) 
    734     char *psz_parent = config_GetUserDir(); 
    735     if( !psz_parent ) psz_parent = p_libvlc->psz_homedir; 
    736     if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 ) 
    737         return NULL; 
    738     return psz_dir; 
    739 #else 
    740     /* XDG Base Directory Specification - Version 0.6 */ 
    741     char *psz_env = getenv( "XDG_CONFIG_HOME" ); 
    742     if( psz_env ) 
    743     { 
    744         if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 ) 
    745             return NULL; 
    746         return psz_dir; 
    747     } 
    748     psz_env = getenv( "HOME" ); 
    749     if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */ 
    750     if( asprintf( &psz_dir, "%s/.config/vlc", psz_env ) == -1 ) 
    751         return NULL; 
    752     return psz_dir; 
    753 #endif 
     769    return config_GetFooDir (p_libvlc, "CONFIG", ".config"); 
    754770} 
    755771 
     
    760776char *config_GetUserDataDir( libvlc_int_t *p_libvlc ) 
    761777{ 
    762     char *psz_dir; 
    763 #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS) 
    764     char *psz_parent = config_GetUserDir(); 
    765     if( !psz_parent ) psz_parent = p_libvlc->psz_homedir; 
    766     if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 ) 
    767         return NULL; 
    768     return psz_dir; 
    769 #else 
    770     /* XDG Base Directory Specification - Version 0.6 */ 
    771     char *psz_env = getenv( "XDG_DATA_HOME" ); 
    772     if( psz_env ) 
    773     { 
    774         if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 ) 
    775             return NULL; 
    776         return psz_dir; 
    777     } 
    778     psz_env = getenv( "HOME" ); 
    779     if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */ 
    780     if( asprintf( &psz_dir, "%s/.local/share/vlc", psz_env ) == -1 ) 
    781         return NULL; 
    782     return psz_dir; 
    783 #endif 
     778    return config_GetFooDir (p_libvlc, "DATA", ".local/share"); 
    784779} 
    785780 
     
    790785char *config_GetCacheDir( libvlc_int_t *p_libvlc ) 
    791786{ 
    792     char *psz_dir; 
    793 #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS) 
    794     char *psz_parent = config_GetUserDir(); 
    795     if( !psz_parent ) psz_parent = p_libvlc->psz_homedir; 
    796     if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 ) 
    797         return NULL; 
    798     return psz_dir; 
    799 #else 
    800     /* XDG Base Directory Specification - Version 0.6 */ 
    801     char *psz_env = getenv( "XDG_CACHE_HOME" ); 
    802     if( psz_env ) 
    803     { 
    804         if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 ) 
    805             return NULL; 
    806         return psz_dir; 
    807     } 
    808     psz_env = getenv( "HOME" ); 
    809     if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */ 
    810     if( asprintf( &psz_dir, "%s/.cache/vlc", psz_env ) == -1 ) 
    811         return NULL; 
    812     return psz_dir; 
    813 #endif 
    814 
     787    return config_GetFooDir (p_libvlc, "CACHE", ".cache"); 
     788