summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Drahoš <drahosp@gmail.com>2011-03-25 03:45:13 +0100
committerPeter Drahoš <drahosp@gmail.com>2011-03-25 03:45:13 +0100
commit33adf9e35813dc28c969b5f482f8bce86bcddf42 (patch)
treec1b571040e8b1537477ef6d8be53658910e76ac2
parent717638b3e6a7dacc55dcb51d5d337f88cfe5d316 (diff)
downloadlua-33adf9e35813dc28c969b5f482f8bce86bcddf42.tar.gz
OSX can now detect executable path faster. Fallback is now only for unsupported systems.
-rw-r--r--src/loadlib_rel.c10
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)