[vlc-commits] posix: factor directory environment variables handling

Rémi Denis-Courmont git at videolan.org
Tue Mar 6 20:17:29 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar  4 15:21:37 2018 +0200| [975216d6a8958f6bbd9cca7ca764b440158deee3] | committer: Rémi Denis-Courmont

posix: factor directory environment variables handling

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=975216d6a8958f6bbd9cca7ca764b440158deee3
---

 src/linux/dirs.c |  5 +----
 src/posix/dirs.c | 21 +++++++++++++++------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/linux/dirs.c b/src/linux/dirs.c
index 466ddcaedb..32e138d866 100644
--- a/src/linux/dirs.c
+++ b/src/linux/dirs.c
@@ -33,10 +33,7 @@
 
 static char *config_GetLibDirRaw(void)
 {
-    char *path = getenv("VLC_LIB_PATH");
-    if (path != NULL)
-        return strdup(path);
-
+    char *path = NULL;
     /* Find the path to libvlc (i.e. ourselves) */
     FILE *maps = fopen ("/proc/self/maps", "rte");
     if (maps == NULL)
diff --git a/src/posix/dirs.c b/src/posix/dirs.c
index 0868773fe3..b8feb8ed65 100644
--- a/src/posix/dirs.c
+++ b/src/posix/dirs.c
@@ -42,8 +42,7 @@
  */
 VLC_WEAK char *config_GetLibDir(void)
 {
-    const char *path = getenv("VLC_LIB_PATH");
-    return strdup((path != NULL) ? path : PKGLIBDIR);
+    return strdup(PKGLIBDIR);
 }
 
 /**
@@ -53,10 +52,6 @@ VLC_WEAK char *config_GetLibDir(void)
  */
 static char *config_GetDataDir(void)
 {
-    const char *path = getenv("VLC_DATA_PATH");
-    if (path != NULL)
-        return strdup(path);
-
     char *libdir = config_GetLibDir();
     if (libdir == NULL)
         return NULL; /* OOM */
@@ -85,6 +80,20 @@ static char *config_GetDataDir(void)
 
 char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
 {
+    static const char env_vars[][16] = {
+        [VLC_PKG_LIB_DIR] = "VLC_LIB_PATH",
+        [VLC_PKG_DATA_DIR] = "VLC_DATA_PATH",
+    };
+
+    if (type < ARRAY_SIZE(env_vars)) {
+        const char *name = env_vars[type];
+         if (*name != '\0') {
+             const char *value = getenv(name);
+             if (value != NULL)
+                 return strdup(value);
+         }
+    }
+
     char *dir;
 
     switch (type)



More information about the vlc-commits mailing list