Browse Source

Don't use NULL in realpath() on darwin, doesn't work in older versions

Thanks to Peter Griess <pg@std.in> for the bug report.
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
1b5ec7017d
  1. 15
      src/platform_darwin.cc

15
src/platform_darwin.cc

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

Loading…
Cancel
Save