|
|
@ -4,6 +4,7 @@ |
|
|
|
#include <mach/task.h> |
|
|
|
#include <mach/mach_init.h> |
|
|
|
#include <mach-o/dyld.h> /* _NSGetExecutablePath */ |
|
|
|
#include <limits.h> /* PATH_MAX */ |
|
|
|
|
|
|
|
namespace node { |
|
|
|
|
|
|
@ -31,10 +32,16 @@ int OS::GetExecutablePath(char* buffer, size_t* size) { |
|
|
|
uint32_t usize = *size; |
|
|
|
int result = _NSGetExecutablePath(buffer, &usize); |
|
|
|
if (result) return result; |
|
|
|
char *path = realpath(buffer, NULL); |
|
|
|
if (path == NULL) return -1; |
|
|
|
strncpy(buffer, path, *size); |
|
|
|
free(path); |
|
|
|
|
|
|
|
char *path = new char[2*PATH_MAX]; |
|
|
|
|
|
|
|
char *fullpath = realpath(buffer, path); |
|
|
|
if (fullpath == NULL) { |
|
|
|
delete [] path; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
strncpy(buffer, fullpath, *size); |
|
|
|
delete [] fullpath; |
|
|
|
*size = strlen(buffer); |
|
|
|
return 0; |
|
|
|
} |
|
|
|