This will avoid adding plenty of config_GetFoobarDir exports later.
Also make config_GetHomeDir return a heap-allocated string.
VLC_EXPORT(const char *, config_GetDataDir, ( void ) LIBVLC_USED);
VLC_EXPORT(const char *, config_GetConfDir, ( void ) LIBVLC_USED);
-VLC_EXPORT(const char *, config_GetHomeDir, ( void ) LIBVLC_USED);
VLC_EXPORT(char *, config_GetUserConfDir, ( void ) LIBVLC_USED);
VLC_EXPORT(char *, config_GetUserDataDir, ( void ) LIBVLC_USED);
+
+typedef enum vlc_userdir {
+ VLC_HOME_DIR,
+} vlc_userdir_t;
+
+VLC_EXPORT(char *, config_GetUserDir, ( vlc_userdir_t ) LIBVLC_USED);
VLC_EXPORT(char *, config_GetCacheDir, ( void ) LIBVLC_USED);
VLC_EXPORT( void, __config_AddIntf, ( vlc_object_t *, const char * ) );
// and there is an off-by-one in the following sprintf().
return;
- const char *home = config_GetHomeDir();
+ char *dir = config_GetUserDir( VLC_HOME_DIR );
+ if( dir == NULL )
+ return;
/* Hmm what about the extension?? */
- char filename[strlen (home) + sizeof ("/vlcdump-YYYYYYYYY-MM-DD-HH-MM-SS.ts")];
- sprintf (filename, "%s/vlcdump-%04u-%02u-%02u-%02u-%02u-%02u.ts", home,
+ char filename[strlen (dir) + sizeof ("/vlcdump-YYYYYYYYY-MM-DD-HH-MM-SS.ts")];
+ sprintf (filename, "%s/vlcdump-%04u-%02u-%02u-%02u-%02u-%02u.ts", dir,
t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
+ free( dir );
msg_Info (access, "dumping media to \"%s\"...", filename);
if( psz_dir[0] == '~' )
{
- char *dir;
- asprintf( &dir, "%s%s", config_GetHomeDir(), psz_dir + 1 );
+ char *home = config_GetUserDir( VLC_HOME_DIR ), *dir;
+ asprintf( &dir, "%s%s", home, psz_dir + 1 );
free( psz_dir );
+ free( home );
psz_dir = dir;
}
if( p_box->i_type == FOURCC_drms )
{
- p_box->data.p_sample_soun->p_drms =
- drms_alloc( config_GetHomeDir() );
-
- if( p_box->data.p_sample_soun->p_drms == NULL )
+ char *home = config_GetUserDir( VLC_HOME_DIR );
+ if( home != NULL )
{
- msg_Err( p_stream, "drms_alloc() failed" );
+ p_box->data.p_sample_soun->p_drms = drms_alloc( home );
+ if( p_box->data.p_sample_soun->p_drms == NULL )
+ msg_Err( p_stream, "drms_alloc() failed" );
}
}
if( p_box->i_type == FOURCC_drmi )
{
- p_box->data.p_sample_vide->p_drms =
- drms_alloc( config_GetHomeDir() );
-
- if( p_box->data.p_sample_vide->p_drms == NULL )
+ char *home = config_GetUserDir( VLC_HOME_DIR );
+ if( home != NULL )
{
- msg_Err( p_stream, "drms_alloc() failed" );
+ p_box->data.p_sample_vide->p_drms = drms_alloc( home );
+ if( p_box->data.p_sample_vide->p_drms == NULL )
+ msg_Err( p_stream, "drms_alloc() failed" );
}
}
p_sys->psz_current_dir = psz_tmp;
else
{
- p_sys->psz_current_dir = strdup( config_GetHomeDir() );
+ p_sys->psz_current_dir = config_GetUserDir( VLC_HOME_DIR );
free( psz_tmp );
}
void FileConfigControl::updateField()
{
QString file = QFileDialog::getOpenFileName( NULL,
- qtr( "Select File" ), qfu( config_GetHomeDir() ) );
+ qtr( "Select File" ), QVLCUserDir( VLC_HOME_DIR ) );
if( file.isNull() ) return;
text->setText( toNativeSeparators( file ) );
}
QString dir = QFileDialog::getExistingDirectory( NULL,
qtr( "Select Directory" ),
text->text().isEmpty() ?
- qfu( config_GetHomeDir() ) : text->text(),
+ QVLCUserDir( VLC_HOME_DIR ) : text->text(),
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
if( dir.isNull() ) return;
{
QString dest_dir = QFileDialog::getExistingDirectory( this,
qtr( "Select a directory..." ),
- qfu( config_GetHomeDir() ) );
+ QVLCUserDir( VLC_DOWNLOAD_DIR ) );
if( !dest_dir.isEmpty() )
{
{
QString saveLogFileName = QFileDialog::getSaveFileName(
this, qtr( "Save log file as..." ),
- qfu( config_GetHomeDir() ),
+ QVLCUserDir( VLC_HOME_DIR ),
qtr( "Texts / Logs (*.log *.txt);; All (*.*) ") );
if( !saveLogFileName.isNull() )
{
QString saveVLMConfFileName = QFileDialog::getSaveFileName( this,
qtr( "Save VLM configuration as..." ),
- qfu( config_GetHomeDir() ),
+ QVLCUserDir( VLC_HOME_DIR ),
qtr( "VLM conf (*.vlm);;All (*)" ) );
if( !saveVLMConfFileName.isEmpty() )
QString openVLMConfFileName = toNativeSeparators(
QFileDialog::getOpenFileName(
this, qtr( "Open VLM configuration..." ),
- qfu( config_GetHomeDir() ),
+ QVLCUserDir( VLC_HOME_DIR ),
qtr( "VLM conf (*.vlm);;All (*)" ) ) );
if( !openVLMConfFileName.isEmpty() )
/* Retrieve last known path used in file browsing */
p_intf->p_sys->filepath =
- getSettings()->value( "filedialog-path", config_GetHomeDir() ).toString();
+ getSettings()->value( "filedialog-path", QVLCUserDir( VLC_HOME_DIR ) ).toString();
/* Loads and tries to apply the preferred QStyle */
QString s_style = getSettings()->value( "MainWindow/QtStyle", "" ).toString();
#define getSettings() p_intf->p_sys->mainSettings
+static inline QString QVLCUserDir( vlc_userdir_t type )
+{
+ char *dir = config_GetUserDir( type );
+ if( !dir )
+ abort();
+ QString res = qfu( dir );
+ free( dir );
+ return res;
+}
#endif
if( !psz_file )
{
#ifdef __APPLE__
- if( asprintf( &psz_file, "%s/"LOG_DIR"/%s", config_GetHomeDir(),
+ char *home = config_GetUserDir(VLC_HOME_DIR);
+ if( home == NULL
+ || asprintf( &psz_file, "%s/"LOG_DIR"/%s", home,
(p_sys->msg.i_mode == MODE_HTML) ? LOG_FILE_HTML
: LOG_FILE_TEXT ) == -1 )
psz_file = NULL;
+ free(home);
#else
switch( p_sys->msg.i_mode )
{
static int vlclua_homedir( lua_State *L )
{
- lua_pushstring( L, config_GetHomeDir() );
+ char *home = config_GetUserDir( VLC_HOME_DIR );
+ lua_pushstring( L, home );
+ free( home );
return 1;
}
psz_extension = "dat";
/* Retreive path */
- char *psz_path = var_CreateGetString( s, "input-record-path" );
- if( !psz_path || *psz_path == '\0' )
- {
- free( psz_path );
- psz_path = strdup( config_GetHomeDir() );
- }
+ char *psz_path = var_CreateGetNonEmptyString( s, "input-record-path" );
+ if( !psz_path )
+ psz_path = config_GetUserDir( VLC_HOME_DIR );
if( !psz_path )
return VLC_ENOMEM;
p_sys->psz_prefix = var_CreateGetString( p_this, CFG_PREFIX "prefix" );
p_sys->psz_path = var_GetNonEmptyString( p_this, CFG_PREFIX "path" );
if( p_sys->psz_path == NULL )
- {
- const char *psz_homedir = config_GetHomeDir();
- if( psz_homedir )
- p_sys->psz_path = strdup( psz_homedir );
- }
+ p_sys->psz_path = config_GetUserDir( VLC_HOME_DIR );
p_filter->pf_video_filter = Filter;
#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)
+{
+#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
+}
+
+char *config_GetUserDir (vlc_userdir_t type)
{
- return GetDir (false, false);
+ char *home = config_GetHomeDir ();
+ (void)type;
+ return home;
}
static char *config_GetFooDir (const char *xdg_name, const char *xdg_default)
/* 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_GetUserDir (VLC_HOME_DIR);
+ 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;
}
{
/* This is the fallback for pre XDG Base Directory
* Specification configs */
+ char *home = config_GetUserDir(VLC_HOME_DIR);
char *psz_old;
- if( asprintf( &psz_old, "%s" DIR_SEP CONFIG_DIR DIR_SEP CONFIG_FILE,
- config_GetHomeDir() ) != -1 )
+
+ if( home != NULL
+ && asprintf( &psz_old, "%s" DIR_SEP CONFIG_DIR DIR_SEP CONFIG_FILE,
+ home ) != -1 )
{
p_stream = utf8_fopen( psz_old, "rt" );
if( p_stream )
"VLC will now use %s.", psz_old, psz_filename );
char *psz_readme;
if( asprintf(&psz_readme,"%s"DIR_SEP CONFIG_DIR DIR_SEP"README",
- config_GetHomeDir() ) != -1 )
+ home ) != -1 )
{
FILE *p_readme = utf8_fopen( psz_readme, "wt" );
if( p_readme )
}
free( psz_old );
}
+ free( home );
}
#endif
free( psz_filename );
if( b_record )
{
- char *psz_path = var_CreateGetString( p_input, "input-record-path" );
- if( !psz_path || *psz_path == '\0' )
- {
- free( psz_path );
- psz_path = strdup( config_GetHomeDir() );
- }
+ char *psz_path = var_CreateGetNonEmptyString( p_input, "input-record-path" );
+ if( !psz_path )
+ psz_path = config_GetUserDir(VLC_HOME_DIR);
char *psz_sout = NULL; // TODO conf
config_GetConfDir
config_GetDataDir
__config_GetFloat
-config_GetHomeDir
+config_GetUserDir
__config_GetInt
__config_GetPsz
__config_GetType
/* */
char *vout_snapshot_GetDirectory(void)
{
- char *psz_path = NULL;
-#if defined(__APPLE__) || defined(SYS_BEOS)
-
- if (asprintf(&psz_path, "%s/Desktop",
- config_GetHomeDir()) == -1)
- psz_path = NULL;
-
-#elif defined(WIN32) && !defined(UNDER_CE)
-
- /* Get the My Pictures folder path */
- char *p_mypicturesdir = NULL;
- typedef HRESULT (WINAPI *SHGETFOLDERPATH)(HWND, int, HANDLE, DWORD,
- LPWSTR);
- #ifndef CSIDL_FLAG_CREATE
- # define CSIDL_FLAG_CREATE 0x8000
- #endif
- #ifndef CSIDL_MYPICTURES
- # define CSIDL_MYPICTURES 0x27
- #endif
- #ifndef SHGFP_TYPE_CURRENT
- # define SHGFP_TYPE_CURRENT 0
- #endif
-
- HINSTANCE shfolder_dll;
- SHGETFOLDERPATH SHGetFolderPath ;
-
- /* load the shfolder dll to retrieve SHGetFolderPath */
- if ((shfolder_dll = LoadLibrary(_T("SHFolder.dll"))) != NULL)
- {
- wchar_t wdir[PATH_MAX];
- SHGetFolderPath = (void *)GetProcAddress(shfolder_dll,
- _T("SHGetFolderPathW"));
- if ((SHGetFolderPath != NULL)
- && SUCCEEDED (SHGetFolderPath (NULL,
- CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
- NULL, SHGFP_TYPE_CURRENT,
- wdir)))
- p_mypicturesdir = FromWide (wdir);
-
- FreeLibrary(shfolder_dll);
- }
-
- if (p_mypicturesdir == NULL)
- psz_path = strdup(config_GetHomeDir());
- else
- psz_path = p_mypicturesdir;
-
-#else
-
- /* XXX: This saves in the data directory. Shouldn't we try saving
- * to psz_homedir/Desktop or something nicer ? */
- char *psz_datadir = config_GetUserDataDir();
- if (psz_datadir)
- {
- if (asprintf(&psz_path, "%s", psz_datadir) == -1)
- psz_path = NULL;
- free(psz_datadir);
- }
-
-#endif
- return psz_path;
+ return config_GetUserDir(VLC_HOME_DIR);
}
/* */
int vout_snapshot_SaveImage(char **name, int *sequential,