Use uv_exepath
authorRyan Dahl <ry@tinyclouds.org>
Fri, 15 Jul 2011 17:46:11 +0000 (10:46 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Fri, 15 Jul 2011 17:46:11 +0000 (10:46 -0700)
src/node.cc
src/platform.h
src/platform_cygwin.cc
src/platform_darwin.cc
src/platform_freebsd.cc
src/platform_linux.cc
src/platform_none.cc
src/platform_openbsd.cc
src/platform_sunos.cc
src/platform_win32.cc

index 03f7e30..78ac8a8 100644 (file)
@@ -2115,7 +2115,7 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
 
   size_t size = 2*PATH_MAX;
   char execPath[size];
-  if (Platform::GetExecutablePath(execPath, &size) != 0) {
+  if (uv_exepath(execPath, &size) != 0) {
     // as a last ditch effort, fallback on argv[0] ?
     process->Set(String::NewSymbol("execPath"), String::New(argv[0]));
   } else {
index a0b45b9..408d478 100644 (file)
@@ -33,7 +33,6 @@ class Platform {
   static const char* GetProcessTitle(int *len);
 
   static int GetMemory(size_t *rss, size_t *vsize);
-  static int GetExecutablePath(char* buffer, size_t* size);
   static int GetCPUInfo(v8::Local<v8::Array> *cpus);
   static double GetFreeMemory();
   static double GetTotalMemory();
index 77e48ca..590cb28 100644 (file)
@@ -264,13 +264,6 @@ error:
 }
 
 
-int Platform::GetExecutablePath(char* buffer, size_t* size) {
-  *size = readlink("/proc/self/exe", buffer, *size - 1);
-  if (*size <= 0) return -1;
-  buffer[*size] = '\0';
-  return 0;
-}
-
 int Platform::GetCPUInfo(Local<Array> *cpus) {
   HandleScope scope;
   Local<Object> cpuinfo;
index deaf629..a64597c 100644 (file)
@@ -27,7 +27,6 @@
 #include <mach/task.h>
 #include <mach/mach.h>
 #include <mach/mach_host.h>
-#include <mach-o/dyld.h> /* _NSGetExecutablePath */
 #include <limits.h> /* PATH_MAX */
 
 #include <unistd.h>  // sysconf
@@ -90,24 +89,6 @@ int Platform::GetMemory(size_t *rss, size_t *vsize) {
 }
 
 
-int Platform::GetExecutablePath(char* buffer, size_t* size) {
-  uint32_t usize = *size;
-  int result = _NSGetExecutablePath(buffer, &usize);
-  if (result) return result;
-
-  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;
-}
-
 int Platform::GetCPUInfo(Local<Array> *cpus) {
   Local<Object> cpuinfo;
   Local<Object> cputimes;
index 7037f11..ce7830c 100644 (file)
@@ -94,20 +94,6 @@ error:
 }
 
 
-int Platform::GetExecutablePath(char* buffer, size_t* size) {
-  int mib[4];
-  mib[0] = CTL_KERN;
-  mib[1] = KERN_PROC;
-  mib[2] = KERN_PROC_PATHNAME;
-  mib[3] = -1;
-
-  if (sysctl(mib, 4, buffer, size, NULL, 0) == -1) {
-    return -1;
-  }
-  *size-=1;
-  return 0;
-}
-
 int Platform::GetCPUInfo(Local<Array> *cpus) {
   Local<Object> cpuinfo;
   Local<Object> cputimes;
index 827b8d4..f8454eb 100644 (file)
@@ -181,13 +181,6 @@ error:
 }
 
 
-int Platform::GetExecutablePath(char* buffer, size_t* size) {
-  *size = readlink("/proc/self/exe", buffer, *size - 1);
-  if (*size <= 0) return -1;
-  buffer[*size] = '\0';
-  return 0;
-}
-
 int Platform::GetCPUInfo(Local<Array> *cpus) {
   HandleScope scope;
   Local<Object> cpuinfo;
index e6d595b..6d92f03 100644 (file)
@@ -49,9 +49,5 @@ int OS::GetMemory(size_t *rss, size_t *vsize) {
   return 0;
 }
 
-int OS::GetExecutablePath(char *buffer, size_t* size) {
-  *size = 0;
-  return -1;
-}
 
 }  // namespace node
index 9a9ba01..50b4cac 100644 (file)
@@ -94,11 +94,6 @@ error:
 }
 
 
-int Platform::GetExecutablePath(char* buffer, size_t* size) {
-  *size = 0;
-  return -1;
-}
-
 int Platform::GetCPUInfo(Local<Array> *cpus) {
   Local<Object> cpuinfo;
   Local<Object> cputimes;
index 76946fd..1897b0d 100644 (file)
@@ -106,25 +106,6 @@ int Platform::GetMemory(size_t *rss, size_t *vsize) {
 }
 
 
-int Platform::GetExecutablePath(char* buffer, size_t* size) {
-  const char *execname = getexecname();
-  if (!execname) return -1;
-  if (execname[0] == '/') {
-    char *result = strncpy(buffer, execname, *size);
-    *size = strlen(result);
-  } else {
-    char *result = getcwd(buffer, *size);
-    if (!result) return -1;
-    result = strncat(buffer, "/", *size);
-    if (!result) return -1;
-    result = strncat(buffer, execname, *size);
-    if (!result) return -1;
-    *size = strlen(result);
-  }
-  return 0;
-}
-
-
 static Handle<Value> data_named(kstat_named_t *knp) {
   Handle<Value> val;
 
index d5a15d6..2a68119 100644 (file)
@@ -231,12 +231,6 @@ double Platform::GetTotalMemory() {
 }
 
 
-int Platform::GetExecutablePath(char* buffer, size_t* size) {
-  *size = 0;
-  return -1;
-}
-
-
 int Platform::GetCPUInfo(Local<Array> *cpus) {
   return -1;
 }