[vlc-commits] config: add more generic config_GetSysDir()
Rémi Denis-Courmont
git at videolan.org
Tue Mar 6 20:17:24 CET 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar 3 18:01:11 2018 +0200| [5acf93221176ebc83e5b097e4ae78b5f8014836b] | committer: 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5acf93221176ebc83e5b097e4ae78b5f8014836b
---
include/vlc_configuration.h | 27 ++++++++++++++++++++++++++-
src/darwin/dirs.c | 25 +++++++++++++++++++++++++
src/libvlccore.sym | 1 +
src/os2/dirs.c | 25 +++++++++++++++++++++++++
src/posix/dirs.c | 26 ++++++++++++++++++++++++++
src/win32/dirs.c | 26 ++++++++++++++++++++++++++
6 files changed, 129 insertions(+), 1 deletion(-)
diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h
index 8421c370f4..f0906da03a 100644
--- a/include/vlc_configuration.h
+++ b/include/vlc_configuration.h
@@ -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 */
diff --git a/src/darwin/dirs.c b/src/darwin/dirs.c
index 9fb15b6dcf..59d60c0fd6 100644
--- a/src/darwin/dirs.c
+++ b/src/darwin/dirs.c
@@ -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");
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 740b3b53f8..6ed142207e 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -54,6 +54,7 @@ config_FindConfig
config_GetDataDir
config_GetLibDir
config_GetFloat
+config_GetSysPath
config_GetUserDir
config_GetInt
config_GetIntChoices
diff --git a/src/os2/dirs.c b/src/os2/dirs.c
index f5753df209..27a1d8a7c6 100644
--- a/src/os2/dirs.c
+++ b/src/os2/dirs.c
@@ -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");
diff --git a/src/posix/dirs.c b/src/posix/dirs.c
index 0514a41a6a..493a67190d 100644
--- a/src/posix/dirs.c
+++ b/src/posix/dirs.c
@@ -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 */
diff --git a/src/win32/dirs.c b/src/win32/dirs.c
index 5e5dd09570..0cbb063780 100644
--- a/src/win32/dirs.c
+++ b/src/win32/dirs.c
@@ -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];
More information about the vlc-commits
mailing list