[libbluray-devel] Win32: search for libbluray.jar from libbluray installation directory
hpi1
git at videolan.org
Sun Feb 3 13:38:07 CET 2013
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sun Feb 3 13:40:44 2013 +0200| [5f0ddf4bf82a0641258c40e9e3164caf876c0c05] | committer: hpi1
Win32: search for libbluray.jar from libbluray installation directory
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=5f0ddf4bf82a0641258c40e9e3164caf876c0c05
---
src/file/dl.h | 9 +++++++++
src/file/dl_posix.c | 42 ++++++++++++++++++++++++++++++++++++++++++
src/libbluray/bdj/bdj.c | 13 +++++++++++++
3 files changed, 64 insertions(+)
diff --git a/src/file/dl.h b/src/file/dl.h
index e379425..0e8ed47 100644
--- a/src/file/dl.h
+++ b/src/file/dl.h
@@ -33,4 +33,13 @@ BD_PRIVATE void *dl_dlopen ( const char* path, const char *version );
BD_PRIVATE void *dl_dlsym ( void* handle, const char* symbol );
BD_PRIVATE int dl_dlclose ( void* handle );
+/*
+ * Installation path of currently running libbluray.so
+ * returns NULL if unknown.
+ *
+ * This function is used to help finding libbluray.jar if location
+ * is not given in LIBBLURAY_CP environment variable.
+ */
+BD_PRIVATE const char *dl_get_path(void);
+
#endif /* DL_H_ */
diff --git a/src/file/dl_posix.c b/src/file/dl_posix.c
index 63586b7..6b76bf0 100644
--- a/src/file/dl_posix.c
+++ b/src/file/dl_posix.c
@@ -35,6 +35,8 @@
# include <sys/dl.h>
#endif
+#include <string.h>
+
#if defined(_WIN32)
static const char *dlerror(char *buf, int buf_size)
{
@@ -160,3 +162,43 @@ int dl_dlclose ( void* handle )
return dlclose(handle);
#endif
}
+
+
+#ifdef WIN32
+ #define PATH_SEPARATOR '\\'
+#else
+ #define PATH_SEPARATOR '/'
+#endif
+
+const char *dl_get_path(void)
+{
+ static char *lib_path = NULL;
+ static int initialized = 0;
+
+ if (!initialized) {
+ initialized = 1;
+
+#ifdef WIN32
+ static char path[MAX_PATH];
+ HMODULE hModule;
+ wchar_t wpath[MAX_PATH];
+
+ GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCTSTR)&dl_get_path, &hModule);
+ GetModuleFileNameW(hModule, wpath, MAX_PATH);
+ WideCharToMultiByte(CP_UTF8, 0, wpath, -1, path, MAX_PATH, NULL, NULL);
+ lib_path = path;
+#endif
+ if (lib_path) {
+ /* cut library name from path */
+ char *p = strrchr(lib_path, PATH_SEPARATOR);
+ if (p) {
+ *(p+1) = 0;
+ }
+ BD_DEBUG(DBG_FILE, "library file is %s\n", lib_path);
+ } else {
+ BD_DEBUG(DBG_FILE, "Can't determine libbluray.so install path\n");
+ }
+ }
+
+ return lib_path;
+}
diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index b142d5e..e7f6944 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -98,6 +98,19 @@ static const char *_find_libbluray_jar(void)
BD_DEBUG(DBG_BDJ, "LIBBLURAY_CP not set, searching for "BDJ_JARFILE" ...\n");
+ // check directory where libbluray.so was loaded from
+ const char *lib_path = dl_get_path();
+ if (lib_path) {
+ char *cp = str_printf("%s" BDJ_JARFILE, lib_path);
+ BD_DEBUG(DBG_BDJ, "Checking %s ...\n", cp);
+ if (!stat(cp, &sb)) {
+ classpath = cp;
+ BD_DEBUG(DBG_BDJ, "using %s\n", cp);
+ return cp;
+ }
+ X_FREE(cp);
+ }
+
// check pre-defined directories
for (i = 0; i < sizeof(jar_paths) / sizeof(jar_paths[0]); i++) {
BD_DEBUG(DBG_BDJ, "Checking %s ...\n", jar_paths[i]);
More information about the libbluray-devel
mailing list