[vlc-devel] commit: Store the home directory statically, as it cannot change ( 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:18:12 2008 +0300| [b152c831cf6bd6dab1fe8e29859ea85d9f384022]
Store the home directory statically, as it cannot change
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b152c831cf6bd6dab1fe8e29859ea85d9f384022
---
src/config/dirs.c | 80 +++++++++++++++++++++++++++++++----------------------
1 files changed, 47 insertions(+), 33 deletions(-)
diff --git a/src/config/dirs.c b/src/config/dirs.c
index e651197..de1a1c7 100644
--- a/src/config/dirs.c
+++ b/src/config/dirs.c
@@ -90,50 +90,64 @@ const char *config_GetConfDir( void )
#endif
}
-static char *GetDir( bool b_appdata )
+static const char *GetDir( bool b_appdata )
{
- const char *psz_localhome = NULL;
+ static char homedir[PATH_MAX] = "";
-#if defined(WIN32) && !defined(UNDER_CE)
- wchar_t whomedir[MAX_PATH];
+#if defined (WIN32)
+ wchar_t wdir[MAX_PATH];
+
+# if defined (UNDER_CE)
+ if( SHGetSpecialFolderPath( NULL, wdir, CSIDL_APPDATA, 1 ) )
+# else
/* Get the "Application Data" folder for the current user */
if( S_OK == SHGetFolderPathW( NULL,
(b_appdata ? CSIDL_APPDATA : CSIDL_PROFILE) | CSIDL_FLAG_CREATE,
- NULL, SHGFP_TYPE_CURRENT, whomedir ) )
- return FromWide( whomedir );
-
-#elif defined(UNDER_CE)
+ NULL, SHGFP_TYPE_CURRENT, wdir ) )
+# endif
+ {
+ static char appdir[PATH_MAX] = "";
+ WideCharToMultiByte (CP_UTF8, 0, wdir, -1,
+ b_appdata ? appdir : homedir, PATH_MAX,
+ NULL, NULL);
+ return b_appdata ? appdir : homedir;
+ }
+#else
(void)b_appdata;
-#ifndef CSIDL_APPDATA
-# define CSIDL_APPDATA 0x1A
#endif
- wchar_t whomedir[MAX_PATH];
-
- /* get the "Application Data" folder for the current user */
- if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) )
- return FromWide( whomedir );
-#else
- (void)b_appdata;
+#ifdef LIBVLC_USE_PTHREAD
+ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+ pthread_mutex_lock (&lock);
#endif
- psz_localhome = getenv( "HOME" );
-#if defined(HAVE_GETPWUID_R)
- char buf[sysconf (_SC_GETPW_R_SIZE_MAX)];
- if( psz_localhome == NULL )
+ if (!*homedir)
{
- struct passwd pw, *res;
-
- if (!getpwuid_r (getuid (), &pw, buf, sizeof (buf), &res) && res)
- psz_localhome = pw.pw_dir;
+ const char *psz_localhome = getenv( "HOME" );
+#if defined(HAVE_GETPWUID_R)
+ char buf[sysconf (_SC_GETPW_R_SIZE_MAX)];
+ if (psz_localhome == NULL)
+ {
+ struct passwd pw, *res;
+
+ if (!getpwuid_r (getuid (), &pw, buf, sizeof (buf), &res) && res)
+ psz_localhome = pw.pw_dir;
+ }
+#endif
+ if (psz_localhome == NULL)
+ psz_localhome = getenv( "TMP" );
+ if (psz_localhome == NULL)
+ psz_localhome = "/tmp";
+
+ const char *uhomedir = FromLocale (psz_localhome);
+ strncpy (homedir, uhomedir, sizeof (homedir) - 1);
+ homedir[sizeof (homedir) - 1] = '\0';
+ LocaleFree (uhomedir);
}
+#ifdef LIBVLC_USE_PTHREAD
+ pthread_mutex_unlock (&lock);
#endif
- if (psz_localhome == NULL)
- psz_localhome = getenv( "TMP" );
- if (psz_localhome == NULL)
- psz_localhome = "/tmp";
-
- return FromLocaleDup( psz_localhome );
+ return homedir;
}
/**
@@ -141,14 +155,14 @@ static char *GetDir( bool b_appdata )
*/
char *config_GetHomeDir( void )
{
- return GetDir( false );
+ return strdup (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 = GetDir (true);
+ char *psz_parent = strdup (GetDir (true));
if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 )
psz_dir = NULL;
More information about the vlc-devel
mailing list