Commit 5acf9322 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

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.
parent ca621cd7
......@@ -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 */
......
......@@ -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");
......
......@@ -54,6 +54,7 @@ config_FindConfig
config_GetDataDir
config_GetLibDir
config_GetFloat
config_GetSysPath
config_GetUserDir
config_GetInt
config_GetIntChoices
......
......@@ -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");
......
......@@ -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 */
......
......@@ -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];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment