get_exename() for OSX >= 10.9

This commit is contained in:
Mark Probst 2015-05-06 15:36:41 -07:00 committed by Lassi Kortela
parent bc0b56be76
commit 3c10ecc0be
1 changed files with 4 additions and 9 deletions

View File

@ -119,17 +119,12 @@ char *get_exename(char *buf, size_t size)
return buf; return buf;
} }
#elif defined(MACOSX) #elif defined(MACOSX)
#include <ApplicationServices/ApplicationServices.h> #include <mach-o/dyld.h>
char *get_exename(char *buf, size_t size) char *get_exename(char *buf, size_t size)
{ {
ProcessSerialNumber PSN; uint32_t bufsize = (uint32_t)size;
FSRef ref; if (_NSGetExecutablePath(buf, &bufsize))
if (GetCurrentProcess(&PSN) < 0 ||
GetProcessBundleLocation(&PSN, &ref) < 0 ||
FSRefMakePath(&ref, buf, size) < 0)
return NULL; return NULL;
return buf; return buf;
} }
#endif #endif