#include <vlc_common.h>
#if defined( WIN32 )
-# define _WIN32_IE IE5
+# ifndef _WIN32_IE
+# define _WIN32_IE 0x0501
+# endif
# include <w32api.h>
#ifndef UNDER_CE
# include <direct.h>
#endif
}
+#if defined (WIN32) || defined(__APPLE__) || defined (SYS_BEOS)
static const char *GetDir( bool b_appdata, bool b_common_appdata )
{
/* FIXME: a full memory page here - quite a waste... */
#endif
return homedir;
}
+#endif
/**
* Determines the system configuration directory.
#endif
}
-/**
- * Get the user's home directory
- */
-const char *config_GetHomeDir( void )
+static char *config_GetHomeDir (void)
{
- return GetDir (false, false);
+#ifndef WIN32
+ /* 1/ Try $HOME */
+ const char *home = getenv ("HOME");
+#if defined(HAVE_GETPWUID_R)
+ /* 2/ Try /etc/passwd */
+ char buf[sysconf (_SC_GETPW_R_SIZE_MAX)];
+ if (home == NULL)
+ {
+ struct passwd pw, *res;
+
+ if (!getpwuid_r (getuid (), &pw, buf, sizeof (buf), &res) && res)
+ home = pw.pw_dir;
+ }
+#endif
+ /* 3/ Desperately try $TMP */
+ if (home == NULL)
+ home = getenv( "TMP" );
+ /* 4/ Beyond hope, hard-code /tmp */
+ if (home == NULL)
+ home = "/tmp";
+
+ return FromLocaleDup (home);
+
+#else /* WIN32 */
+ wchar_t wdir[MAX_PATH];
+
+# if defined (UNDER_CE)
+ /*There are some errors in cegcc headers*/
+#undef SHGetSpecialFolderPath
+ BOOL WINAPI SHGetSpecialFolderPath(HWND,LPWSTR,int,BOOL);
+ if (SHGetSpecialFolderPath (NULL, wdir, CSIDL_APPDATA, 1))
+# else
+ if (SHGetFolderPathW (NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE,
+ NULL, SHGFP_TYPE_CURRENT, wdir ) == S_OK)
+# endif
+ return FromWide (wdir);
+ return NULL;
+#endif
}
-static char *config_GetFooDir (const char *xdg_name, const char *xdg_default)
+static char *config_GetAppDir (const char *xdg_name, const char *xdg_default)
{
char *psz_dir;
#if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS)
/* XDG Base Directory Specification - Version 0.6 */
snprintf (var, sizeof (var), "XDG_%s_HOME", xdg_name);
- const char *psz_home = getenv (var);
- psz_home = psz_home ? FromLocale (psz_home) : NULL;
+ char *psz_home = FromLocale (getenv (var));
if( psz_home )
{
if( asprintf( &psz_dir, "%s/vlc", psz_home ) == -1 )
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_home = config_GetHomeDir ();
+ if( psz_home == NULL
+ || asprintf( &psz_dir, "%s/%s/vlc", psz_home, xdg_default ) == -1 )
psz_dir = NULL;
+ free (psz_home);
#endif
return psz_dir;
}
-/**
- * Get the user's VLC configuration directory
- */
-char *config_GetUserConfDir( void )
-{
- return config_GetFooDir ("CONFIG", ".config");
-}
-
-/**
- * Get the user's VLC data directory
- * (used for stuff like the skins, custom lua modules, ...)
- */
-char *config_GetUserDataDir( void )
-{
- return config_GetFooDir ("DATA", ".local/share");
-}
-
/**
* Get the user's VLC cache directory
* (used for stuff like the modules cache, the album art cache, ...)
return psz_dir;
#else
- return config_GetFooDir ("CACHE", ".cache");
+ return config_GetAppDir ("CACHE", ".cache");
#endif
}
+
+char *config_GetUserDir (vlc_userdir_t type)
+{
+ switch (type)
+ {
+ case VLC_HOME_DIR:
+ return config_GetHomeDir ();
+ case VLC_CONFIG_DIR:
+ return config_GetAppDir ("CONFIG", ".config");
+ case VLC_DATA_DIR:
+ return config_GetAppDir ("DATA", ".local/share");
+ }
+ assert (0);
+}