mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-21 22:04:56 -06:00
MacOS: GetExeFilePath fix
git-svn-id: svn://ultimatepp.org/upp/trunk@14290 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
c503c52aaa
commit
bb963792f5
1 changed files with 19 additions and 7 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "Core.h"
|
||||
#include <mach-o/dyld.h>
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
#define Ptr Ptr_
|
||||
|
|
@ -83,17 +84,28 @@ extern char Argv0__[];
|
|||
const char *procexepath_() {
|
||||
static char h[_MAX_PATH + 1];
|
||||
ONCELOCK {
|
||||
char link[100];
|
||||
#ifdef PLATFORM_BSD
|
||||
char link[1024];
|
||||
#ifdef PLATFORM_COCOA
|
||||
uint32_t sz = 1024;
|
||||
if(_NSGetExecutablePath(link, &sz))
|
||||
*link = 0;
|
||||
#elif defined(PLATFORM_BSD)
|
||||
sprintf(link, "/proc/%d/file", getpid());
|
||||
#else
|
||||
sprintf(link, "/proc/%d/exe", getpid());
|
||||
#endif
|
||||
int ret = readlink(link, h, _MAX_PATH);
|
||||
if(ret > 0 && ret < _MAX_PATH)
|
||||
h[ret] = '\0';
|
||||
else
|
||||
*h = '\0';
|
||||
FindFile ff(link);
|
||||
if(ff) {
|
||||
if(ff.IsSymLink()) {
|
||||
int ret = readlink(link, h, _MAX_PATH);
|
||||
if(ret > 0 && ret < _MAX_PATH)
|
||||
h[ret] = '\0';
|
||||
else
|
||||
*h = '\0';
|
||||
}
|
||||
else
|
||||
strcpy(h, link);
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue