[vlc-commits] Linux: determine data path at run-time from library path

Rémi Denis-Courmont git at videolan.org
Tue Mar 20 19:32:01 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Mar 20 20:31:32 2012 +0200| [85f5c15fe54e363717cffb21f69dc4cc32eb4ad6] | committer: Rémi Denis-Courmont

Linux: determine data path at run-time from library path

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

 src/Makefile.am            |    2 +-
 src/posix/dirs.c           |    4 ++--
 src/posix/linux_specific.c |   29 ++++++++++++++++++++++++++++-
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index a8cecab..cd06794 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -169,7 +169,7 @@ AM_CPPFLAGS = $(INCICONV) \
 	-DMODULE_STRING=\"main\" \
 	-DLOCALEDIR=\"$(localedir)\" \
 	-DSYSCONFDIR=\"$(sysconfdir)\" \
-	-DDATA_PATH=\"$(vlcdatadir)\" \
+	-DPKGDATADIR=\"$(vlcdatadir)\" \
 	-DPKGLIBDIR=\"$(vlclibdir)\"
 AM_CFLAGS = $(CFLAGS_libvlccore)
 
diff --git a/src/posix/dirs.c b/src/posix/dirs.c
index e23f883..87c7857 100644
--- a/src/posix/dirs.c
+++ b/src/posix/dirs.c
@@ -35,6 +35,7 @@
 #include <assert.h>
 #include <limits.h>
 
+#if !defined (__linux__)
 /**
  * Determines the shared data directory
  *
@@ -42,10 +43,9 @@
  */
 char *config_GetDataDirDefault (void)
 {
-    return strdup (DATA_PATH);
+    return strdup (PKGDATADIR);
 }
 
-#if !defined (__linux__)
 /**
  * Determines the architecture-dependent data directory
  *
diff --git a/src/posix/linux_specific.c b/src/posix/linux_specific.c
index 7cc7a78..f7d8290 100644
--- a/src/posix/linux_specific.c
+++ b/src/posix/linux_specific.c
@@ -26,7 +26,8 @@
 #include <string.h>
 
 #include <vlc_common.h>
-#include "../libvlc.h"
+#include "libvlc.h"
+#include "config/configuration.h"
 
 char *config_GetLibDir (void)
 {
@@ -73,3 +74,29 @@ char *config_GetLibDir (void)
 error:
     return (path != NULL) ? path : strdup (PKGLIBDIR);
 }
+
+char *config_GetDataDirDefault (void)
+{
+    char *libdir = config_GetLibDir ();
+    if (libdir == NULL)
+        return NULL; /* OOM */
+
+    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/");
+    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))
+            datadir = NULL;
+    }
+    free (libdir);
+    return (datadir != NULL) ? datadir : strdup (PKGDATADIR);
+}



More information about the vlc-commits mailing list