Revision 1b5ec701 src/platform_darwin.cc

View differences:

src/platform_darwin.cc
4 4
#include <mach/task.h>
5 5
#include <mach/mach_init.h>
6 6
#include <mach-o/dyld.h> /* _NSGetExecutablePath */
7
#include <limits.h> /* PATH_MAX */
7 8

  
8 9
namespace node {
9 10

  
......
31 32
  uint32_t usize = *size;
32 33
  int result = _NSGetExecutablePath(buffer, &usize);
33 34
  if (result) return result;
34
  char *path = realpath(buffer, NULL);
35
  if (path == NULL) return -1;
36
  strncpy(buffer, path, *size);
37
  free(path);
35

  
36
  char *path = new char[2*PATH_MAX];
37

  
38
  char *fullpath = realpath(buffer, path);
39
  if (fullpath == NULL) {
40
    delete [] path;
41
    return -1;
42
  }
43
  strncpy(buffer, fullpath, *size);
44
  delete [] fullpath;
38 45
  *size = strlen(buffer);
39 46
  return 0;
40 47
}

Also available in: Unified diff