From 7ee49df717efe53087efa3b16080d83ca67bff5f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 14 Apr 2020 09:24:08 +0200 Subject: [PATCH] Chg: updates from whereami repo. I am sure I broke something now --- client/whereami.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/client/whereami.c b/client/whereami.c index 9b154c628..923115318 100644 --- a/client/whereami.c +++ b/client/whereami.c @@ -154,20 +154,28 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) } */ -#elif defined(__linux__) +#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun) || defined(WAI_USE_PROC_SELF_EXE) #include #include #include +#if defined(__linux__) #include +#else +#include +#endif #ifndef __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS #endif #include #if !defined(WAI_PROC_SELF_EXE) +#if defined(__sun) +#define WAI_PROC_SELF_EXE "/proc/self/path/a.out" +#else #define WAI_PROC_SELF_EXE "/proc/self/exe" #endif +#endif WAI_FUNCSPEC int WAI_PREFIX(getExecutablePath)(char *out, int capacity, int *dirname_length) { @@ -207,8 +215,12 @@ int WAI_PREFIX(getExecutablePath)(char *out, int capacity, int *dirname_length) #endif #if !defined(WAI_PROC_SELF_MAPS) +#if defined(__sun) +#define WAI_PROC_SELF_MAPS "/proc/self/map" +#else #define WAI_PROC_SELF_MAPS "/proc/self/maps" #endif +#endif #if defined(__ANDROID__) || defined(ANDROID) #include @@ -260,7 +272,7 @@ int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) { char *begin; char *p; - begin = (char *)mmap(0, offset, PROT_READ, MAP_SHARED, fd, 0); + begin = (char*)mmap(0, offset + sizeof(p), PROT_READ, MAP_SHARED, fd, 0); p = begin + offset; while (p >= begin) { // scan backwards @@ -276,7 +288,7 @@ int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) { break; } - p -= 4; + --p; } munmap(begin, offset); @@ -302,11 +314,15 @@ int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) { } fclose(maps); + maps = NULL; if (length != -1) break; } + if (maps) + fclose(maps); + return length; }