[vlc-commits] linux: fix datadir for some directory layouts

Rémi Denis-Courmont git at videolan.org
Sun Feb 11 09:17:12 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Feb 11 10:14:56 2018 +0200| [1168a84567ef5015b0f8a0bdd63b088be7395e65] | committer: Rémi Denis-Courmont

linux: fix datadir for some directory layouts

This changes the computation of datadir from libdir to a more generic
algorithm where we substitute the common prefix of both directory.

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

 src/linux/dirs.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/linux/dirs.c b/src/linux/dirs.c
index 70753da967..736705ad50 100644
--- a/src/linux/dirs.c
+++ b/src/linux/dirs.c
@@ -111,20 +111,22 @@ char *config_GetDataDir (void)
     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;
 
-    /* There are no clean ways to do this, are there?
-     * Due to multilibs, we cannot simply append ../share/. */
-    char *p = strstr (libdir, "/lib/");
+    char *p = strstr(libdir, PKGLIBDIR + prefix_len);
     if (p != NULL)
     {
-        char *p2;
-        /* Deal with nested "lib" directories. Grmbl. */
-        while ((p2 = strstr (p + 4, "/lib/")) != NULL)
-            p = p2;
-        *p = '\0';
-
-        if (unlikely(asprintf (&datadir, "%s/share/"PACKAGE, libdir) == -1))
+        if (unlikely(asprintf(&datadir, "%.*s%s", (int)(p - libdir), libdir,
+                              PKGDATADIR + prefix_len) == -1))
             datadir = NULL;
     }
     free (libdir);



More information about the vlc-commits mailing list