1
mirror of https://code.videolan.org/videolan/vlc synced 2024-07-21 07:24:15 +02:00

config: add more generic config_GetSysDir()

A quick survey of used installation directories yields those:
datadir, libdir, localedir, pkgdatadir, pkglibdir, pkglibexecdir.

The current pair of functions is up to the requirements. This provides
a more generic function prototype, similar to what is done for user
directories.

Refs #19748, #19894.
This commit is contained in:
Rémi Denis-Courmont 2018-03-03 18:01:11 +02:00
parent ca621cd7f7
commit 5acf932211
6 changed files with 129 additions and 1 deletions

View File

@ -297,7 +297,32 @@ VLC_API char *config_GetDataDir(void) VLC_USED VLC_MALLOC;
*/
VLC_API char *config_GetLibDir(void) VLC_USED VLC_MALLOC;
typedef enum vlc_userdir
/**
* System directory identifiers
*/
typedef enum vlc_system_dir
{
VLC_PKG_DATA_DIR, /**< Package-specific architecture-independent read-only
data directory (e.g. /usr/local/data/vlc). */
VLC_PKG_LIB_DIR, /**< Package-specific architecture-dependent read-only
data directory (e.g. /usr/local/lib/vlc). */
} vlc_sysdir_t;
/**
* Gets an installation directory.
*
* This function determines one of the installation directory.
*
* @param dir identifier of the directory (see \ref vlc_sysdir_t)
* @param filename name of a file or other object within the directory
* (or NULL to obtain the plain directory)
*
* @return a heap-allocated string (use free() to release it), or NULL on error
*/
VLC_API char *config_GetSysPath(vlc_sysdir_t dir, const char *filename)
VLC_USED VLC_MALLOC;
typedef enum vlc_user_dir
{
VLC_HOME_DIR, /* User's home */
VLC_CONFIG_DIR, /* VLC-specific configuration directory */

View File

@ -108,6 +108,31 @@ char *config_GetDataDir (void)
return datadir;
}
char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
{
char *dir;
switch (type)
{
case VLC_PKG_DATA_DIR:
dir = config_GetDataDir();
break;
case VLC_PKG_LIB_DIR:
dir = config_GetLibDir();
break;
default:
vlc_assert_unreachable();
}
if (filename == NULL || unlikely(dir == NULL))
return dir;
char *path;
asprintf(&path, "%s/%s", dir, filename);
free(dir);
return path;
}
static char *config_GetHomeDir (void)
{
const char *home = getenv ("HOME");

View File

@ -54,6 +54,7 @@ config_FindConfig
config_GetDataDir
config_GetLibDir
config_GetFloat
config_GetSysPath
config_GetUserDir
config_GetInt
config_GetIntChoices

View File

@ -64,6 +64,31 @@ char *config_GetDataDir (void)
return datadir;
}
char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
{
char *dir;
switch (type)
{
case VLC_PKG_DATA_DIR:
dir = config_GetDataDir();
break;
case VLC_PKG_LIB_DIR:
dir = config_GetLibDir();
break;
default:
vlc_assert_unreachable();
}
if (filename == NULL || unlikely(dir == NULL))
return dir;
char *path;
asprintf(&path, "%s/%s", dir, filename);
free(dir);
return path;
}
static char *config_GetHomeDir (void)
{
const char *home = getenv ("HOME");

View File

@ -57,6 +57,32 @@ VLC_WEAK char *config_GetLibDir(void)
return strdup((path != NULL) ? path : PKGLIBDIR);
}
char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
{
char *dir;
switch (type)
{
case VLC_PKG_DATA_DIR:
dir = config_GetDataDir();
break;
case VLC_PKG_LIB_DIR:
dir = config_GetLibDir();
break;
default:
vlc_assert_unreachable();
}
if (filename == NULL || unlikely(dir == NULL))
return dir;
char *path;
if (unlikely(asprintf(&path, "%s/%s", dir, filename) == -1))
path = NULL;
free(dir);
return path;
}
static char *config_GetHomeDir (void)
{
/* 1/ Try $HOME */

View File

@ -212,6 +212,32 @@ char *config_GetDataDir (void)
return (path != NULL) ? strdup (path) : config_GetLibDir ();
}
char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
{
char *dir;
switch (type)
{
case VLC_PKG_DATA_DIR:
dir = config_GetDataDir();
break;
case VLC_PKG_LIB_DIR:
dir = config_GetLibDir();
break;
default:
vlc_assert_unreachable();
}
if (filename == NULL || unlikely(dir == NULL))
return dir;
char *path;
if (unlikely(asprintf(&path, "%s/%s", dir, filename) == -1))
path = NULL;
free(dir);
return path;
}
static char *config_GetShellDir (int csidl)
{
wchar_t wdir[MAX_PATH];