[vlc-devel] commit: libvlc os-specific path discovery (Luca Barbato )
git version control
git at videolan.org
Sat Jan 23 17:45:20 CET 2010
vlc | branch: master | Luca Barbato <lu_zero at gentoo.org> | Sat Jan 23 17:41:52 2010 +0100| [c035e8417b7d1ff3df7d95af3a7e34092912db96] | committer: Jean-Baptiste Kempf
libvlc os-specific path discovery
Get the right libvlc path in macosx and win32 to reside in the specific.c files.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c035e8417b7d1ff3df7d95af3a7e34092912db96
---
src/misc/darwin_specific.c | 12 ++++++++++--
src/win32/specific.c | 13 +++++++++----
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/misc/darwin_specific.c b/src/misc/darwin_specific.c
index 0efdd6d..1f74caf 100644
--- a/src/misc/darwin_specific.c
+++ b/src/misc/darwin_specific.c
@@ -30,7 +30,8 @@
#include <vlc_common.h>
#include "../libvlc.h"
#include <dirent.h> /* *dir() */
-
+#include <libgen.h>
+#include <dlfcn.h>
#include <CoreFoundation/CoreFoundation.h>
#include <mach-o/dyld.h>
@@ -79,7 +80,14 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
p_char = NULL;
}
}
-
+ if ( !p_char )
+ {
+ /* We are not linked to the VLC.framework, let's use dladdr to figure
+ * libvlc path */
+ Dl_info info;
+ if( dladdr(system_Init, &info) )
+ p_char = strdup(dirname( info.dli_fname ));
+ }
if( !p_char )
{
char path[MAXPATHLEN+1];
diff --git a/src/win32/specific.c b/src/win32/specific.c
index 66cf781..bf131fb 100644
--- a/src/win32/specific.c
+++ b/src/win32/specific.c
@@ -48,18 +48,23 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
{
VLC_UNUSED( p_this ); VLC_UNUSED( pi_argc ); VLC_UNUSED( ppsz_argv );
WSADATA Data;
+ MEMORY_BASIC_INFORMATION mbi;
/* Get our full path */
char psz_path[MAX_PATH];
char *psz_vlc;
wchar_t psz_wpath[MAX_PATH];
- if( GetModuleFileName( NULL, psz_wpath, MAX_PATH ) )
+ if( VirtualQuery(system_Init, &mbi, sizeof(mbi) ) )
{
- WideCharToMultiByte( CP_UTF8, 0, psz_wpath, -1,
- psz_path, MAX_PATH, NULL, NULL );
+ HMODULE hMod = (HMODULE) mbi.AllocationBase;
+ if( GetModuleFileName( hMod, psz_wpath, MAX_PATH ) )
+ {
+ WideCharToMultiByte( CP_UTF8, 0, psz_wpath, -1,
+ psz_path, MAX_PATH, NULL, NULL );
+ }
+ else psz_path[0] = '\0';
}
- else psz_path[0] = '\0';
if( (psz_vlc = strrchr( psz_path, '\\' )) ) *psz_vlc = '\0';
More information about the vlc-devel
mailing list