diff options
-rw-r--r-- | src/loadlib_rel.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/loadlib_rel.c b/src/loadlib_rel.c index cc21a3d..5ba8d23 100644 --- a/src/loadlib_rel.c +++ b/src/loadlib_rel.c @@ -55,10 +55,16 @@ static void setprogdir (lua_State *L); #else #define _PATH_MAX PATH_MAX #endif + #if defined(__linux__) #include <unistd.h> /* readlink */ #endif +#if defined(__APPLE__) + #include <sys/param.h> + #include <mach-o/dyld.h> +#endif + static void setprogdir (lua_State *L) { char progdir[_PATH_MAX + 1]; char *lb; @@ -77,6 +83,10 @@ static void setprogdir (lua_State *L) { #elif defined(__FreeBSD__) n = readlink("/proc/curproc/file", progdir, nsize); if (n > 0) progdir[n] = 0; +#elif defined(__APPLE__) + uint32_t nsize_apple = nsize; + if (_NSGetExecutablePath(progdir, &nsize_apple) == 0) + n = strlen(progdir); #else // FALLBACK // Use 'lsof' ... should work on most UNIX systems (incl. OSX) |