libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 4b20c0b37ac2034011fc726ec880c2e0aa93cd8e
parent 7de69d369e2c1d36963ceba1954a93cbbdb72294
Author: Heikki Lindholm <holin@iki.fi>
Date:   Tue,  5 Feb 2008 17:35:48 +0000

add OS X specific installation path discovery


Diffstat:
Msrc/include/platform.h | 5+++++
Msrc/main/extractor.c | 39+++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/src/include/platform.h b/src/include/platform.h @@ -60,4 +60,9 @@ #include <iconv.h> #include <langinfo.h> +#if DARWIN +#include <mach-o/dyld.h> +#include <mach-o/ldsyms.h> +#endif + #endif diff --git a/src/main/extractor.c b/src/main/extractor.c @@ -386,6 +386,32 @@ static char * get_path_from_module_filename() { } #endif +#if DARWIN +static char * get_path_from_dyld_image() { + const char * path; + char * p, * s; + int i; + int c; + + p = NULL; + c = _dyld_image_count(); + for (i = 0; i < c; i++) { + if (_dyld_get_image_header(i) == &_mh_dylib_header) { + path = _dyld_get_image_name(i); + if (path != NULL) { + p = strdup(path); + s = p + strlen(p); + while ( (s > p) && (*s != '/') ) + s--; + *s = '\0'; + } + break; + } + } + return p; +} +#endif + /** * This may also fail -- for example, if extract * is not also installed. @@ -451,6 +477,7 @@ static char * os_get_installation_path() { char * lpref; char * pexe; char * modu; + char * dima; char * path; lpref = get_path_from_ENV_PREFIX(); @@ -464,6 +491,11 @@ static char * os_get_installation_path() { #else modu = NULL; #endif +#if DARWIN + dima = get_path_from_dyld_image(); +#else + dima = NULL; +#endif path = get_path_from_PATH(); n = 1; if (lpref != NULL) @@ -472,6 +504,8 @@ static char * os_get_installation_path() { n += strlen(pexe) + strlen("/lib/libextractor/:"); if (modu != NULL) n += strlen(modu) + strlen("/lib/libextractor/:"); + if (dima != NULL) + n += strlen(dima) + strlen("/libextractor/:"); if (path != NULL) n += strlen(path) + strlen("/lib/libextractor/:"); tmp = malloc(n); @@ -491,6 +525,11 @@ static char * os_get_installation_path() { strcat(tmp, "/lib/libextractor/:"); free(modu); } + if (dima != NULL) { + strcat(tmp, dima); + strcat(tmp, "/libextractor/:"); + free(dima); + } if (path != NULL) { strcat(tmp, path); strcat(tmp, "/lib/libextractor/:");