[vlc-commits] posix: merge Linux config_GetDataDir()

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


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

posix: merge Linux config_GetDataDir()

There are no needs to distinguish Linux for standard here.
Also make config_GetDataDir() static.

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

 src/config/configuration.h | 18 ------------------
 src/darwin/dirs.c          |  2 +-
 src/linux/dirs.c           | 32 --------------------------------
 src/os2/dirs.c             |  2 +-
 src/posix/dirs.c           | 46 ++++++++++++++++++++++++++++++++++++----------
 src/win32/dirs.c           |  2 +-
 6 files changed, 39 insertions(+), 63 deletions(-)

diff --git a/src/config/configuration.h b/src/config/configuration.h
index f8489e607a..ec19abc89e 100644
--- a/src/config/configuration.h
+++ b/src/config/configuration.h
@@ -56,29 +56,11 @@ extern bool config_dirty;
 bool config_IsSafe (const char *);
 
 /**
- * Gets the arch-independent installation directory.
- *
- * This function determines the directory containing the
- * architecture-independent installed asset files (such as image, text and
- * message translation tables).
- *
- * See also config_GetLibDir().
- *
- * @return a heap-allocated string (use free() to release it), or NULL on error
- */
-char *config_GetDataDir(void) VLC_USED VLC_MALLOC;
-
-/**
  * Gets the arch-specific installation directory.
  *
  * This function determines the directory containing the architecture-specific
  * installed asset files (such as executable plugins and compiled byte code).
  *
- * See also config_GetDataDir().
- *
- * \note config_GetDataDir() and config_GetLibDir() may or may not return the
- * same path, depending on conventions of the operating system.
- *
  * @return a heap-allocated string (use free() to release it), or NULL on error
  */
 char *config_GetLibDir(void) VLC_USED VLC_MALLOC;
diff --git a/src/darwin/dirs.c b/src/darwin/dirs.c
index 59d60c0fd6..8b427163f7 100644
--- a/src/darwin/dirs.c
+++ b/src/darwin/dirs.c
@@ -92,7 +92,7 @@ char *config_GetLibDir (void)
     abort ();
 }
 
-char *config_GetDataDir (void)
+static char *config_GetDataDir(void)
 {
     const char *path = getenv ("VLC_DATA_PATH");
     if (path)
diff --git a/src/linux/dirs.c b/src/linux/dirs.c
index 736705ad50..466ddcaedb 100644
--- a/src/linux/dirs.c
+++ b/src/linux/dirs.c
@@ -100,35 +100,3 @@ char *config_GetLibDir(void)
     pthread_once(&once, config_GetLibDirOnce);
     return strdup(cached_path);
 }
-
-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 */
-
-    /* Look for common prefix between lib and data directories. */
-    size_t prefix_len = 0;
-    while (PKGLIBDIR[prefix_len] == PKGDATADIR[prefix_len])
-    {
-        if (PKGLIBDIR[prefix_len] == '\0')
-            return libdir; /* corner case: directories are identical */
-        prefix_len++;
-    }
-
-    char *datadir = NULL;
-
-    char *p = strstr(libdir, PKGLIBDIR + prefix_len);
-    if (p != NULL)
-    {
-        if (unlikely(asprintf(&datadir, "%.*s%s", (int)(p - libdir), libdir,
-                              PKGDATADIR + prefix_len) == -1))
-            datadir = NULL;
-    }
-    free (libdir);
-    return (datadir != NULL) ? datadir : strdup (PKGDATADIR);
-}
diff --git a/src/os2/dirs.c b/src/os2/dirs.c
index 27a1d8a7c6..552cc2fcd5 100644
--- a/src/os2/dirs.c
+++ b/src/os2/dirs.c
@@ -51,7 +51,7 @@ char *config_GetLibDir (void)
  *
  * @return a nul-terminated string or NULL. Use free() to release it.
  */
-char *config_GetDataDir (void)
+static char *config_GetDataDir(void)
 {
     const char *path = getenv ("VLC_DATA_PATH");
     if (path)
diff --git a/src/posix/dirs.c b/src/posix/dirs.c
index 493a67190d..0868773fe3 100644
--- a/src/posix/dirs.c
+++ b/src/posix/dirs.c
@@ -36,25 +36,51 @@
 #include <limits.h>
 
 /**
- * Determines the shared data directory
+ * Determines the architecture-dependent data directory
  *
- * @return a nul-terminated string or NULL. Use free() to release it.
+ * @return a string (always succeeds).
  */
-VLC_WEAK char *config_GetDataDir(void)
+VLC_WEAK char *config_GetLibDir(void)
 {
-    const char *path = getenv ("VLC_DATA_PATH");
-    return strdup ((path != NULL) ? path : PKGDATADIR);
+    const char *path = getenv("VLC_LIB_PATH");
+    return strdup((path != NULL) ? path : PKGLIBDIR);
 }
 
 /**
- * Determines the architecture-dependent data directory
+ * Determines the shared data directory
  *
- * @return a string (always succeeds).
+ * @return a nul-terminated string or NULL. Use free() to release it.
  */
-VLC_WEAK char *config_GetLibDir(void)
+static char *config_GetDataDir(void)
 {
-    const char *path = getenv("VLC_LIB_PATH");
-    return strdup((path != NULL) ? path : PKGLIBDIR);
+    const char *path = getenv("VLC_DATA_PATH");
+    if (path != NULL)
+        return strdup(path);
+
+    char *libdir = config_GetLibDir();
+    if (libdir == NULL)
+        return NULL; /* OOM */
+
+    /* Look for common prefix between lib and data directories. */
+    size_t prefix_len = 0;
+    while (PKGLIBDIR[prefix_len] == PKGDATADIR[prefix_len])
+    {
+        if (PKGLIBDIR[prefix_len] == '\0')
+            return libdir; /* corner case: directories are identical */
+        prefix_len++;
+    }
+
+    char *datadir = NULL;
+
+    char *p = strstr(libdir, PKGLIBDIR + prefix_len);
+    if (p != NULL)
+    {
+        if (unlikely(asprintf(&datadir, "%.*s%s", (int)(p - libdir), libdir,
+                              PKGDATADIR + prefix_len) == -1))
+            datadir = NULL;
+    }
+    free (libdir);
+    return (datadir != NULL) ? datadir : strdup (PKGDATADIR);
 }
 
 char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
diff --git a/src/win32/dirs.c b/src/win32/dirs.c
index 0cbb063780..f75002072e 100644
--- a/src/win32/dirs.c
+++ b/src/win32/dirs.c
@@ -206,7 +206,7 @@ error:
 #endif
 }
 
-char *config_GetDataDir (void)
+static char *config_GetDataDir(void)
 {
     const char *path = getenv ("VLC_DATA_PATH");
     return (path != NULL) ? strdup (path) : config_GetLibDir ();



More information about the vlc-commits mailing list