[llvm] r184916 - Remove sys::GetMainExecutable.

Rafael Espindola rafael.espindola at gmail.com
Tue Jun 25 22:05:37 PDT 2013


Author: rafael
Date: Wed Jun 26 00:05:37 2013
New Revision: 184916

URL: http://llvm.org/viewvc/llvm-project?rev=184916&view=rev
Log:
Remove sys::GetMainExecutable.

Modified:
    llvm/trunk/include/llvm/Support/PathV1.h
    llvm/trunk/lib/Support/Unix/Path.inc
    llvm/trunk/lib/Support/Windows/Path.inc

Modified: llvm/trunk/include/llvm/Support/PathV1.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PathV1.h?rev=184916&r1=184915&r2=184916&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PathV1.h (original)
+++ llvm/trunk/include/llvm/Support/PathV1.h Wed Jun 26 00:05:37 2013
@@ -104,11 +104,6 @@ namespace sys {
       /// @brief Returns the current working directory.
       static Path GetCurrentDirectory();
 
-      /// GetMainExecutable - Return the path to the main executable, given the
-      /// value of argv[0] from program startup and the address of main itself.
-      /// In extremis, this function may fail and return an empty path.
-      static Path GetMainExecutable(const char *argv0, void *MainAddr);
-
       /// This is one of the very few ways in which a path can be constructed
       /// with a syntactically invalid name. The only *legal* invalid name is an
       /// empty one. Other invalid names are not permitted. Empty paths are

Modified: llvm/trunk/lib/Support/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=184916&r1=184915&r2=184916&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc (original)
+++ llvm/trunk/lib/Support/Unix/Path.inc Wed Jun 26 00:05:37 2013
@@ -190,113 +190,6 @@ Path::GetCurrentDirectory() {
   return Path(pathname);
 }
 
-#if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \
-    defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \
-    defined(__linux__) || defined(__CYGWIN__)
-static int
-test_dir(char buf[PATH_MAX], char ret[PATH_MAX],
-    const char *dir, const char *bin)
-{
-  struct stat sb;
-
-  snprintf(buf, PATH_MAX, "%s/%s", dir, bin);
-  if (realpath(buf, ret) == NULL)
-    return (1);
-  if (stat(buf, &sb) != 0)
-    return (1);
-
-  return (0);
-}
-
-static char *
-getprogpath(char ret[PATH_MAX], const char *bin)
-{
-  char *pv, *s, *t, buf[PATH_MAX];
-
-  /* First approach: absolute path. */
-  if (bin[0] == '/') {
-    if (test_dir(buf, ret, "/", bin) == 0)
-      return (ret);
-    return (NULL);
-  }
-
-  /* Second approach: relative path. */
-  if (strchr(bin, '/') != NULL) {
-    if (getcwd(buf, PATH_MAX) == NULL)
-      return (NULL);
-    if (test_dir(buf, ret, buf, bin) == 0)
-      return (ret);
-    return (NULL);
-  }
-
-  /* Third approach: $PATH */
-  if ((pv = getenv("PATH")) == NULL)
-    return (NULL);
-  s = pv = strdup(pv);
-  if (pv == NULL)
-    return (NULL);
-  while ((t = strsep(&s, ":")) != NULL) {
-    if (test_dir(buf, ret, t, bin) == 0) {
-      free(pv);
-      return (ret);
-    }
-  }
-  free(pv);
-  return (NULL);
-}
-#endif // __FreeBSD__ || __NetBSD__ || __FreeBSD_kernel__
-
-/// GetMainExecutable - Return the path to the main executable, given the
-/// value of argv[0] from program startup.
-Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {
-#if defined(__APPLE__)
-  // On OS X the executable path is saved to the stack by dyld. Reading it
-  // from there is much faster than calling dladdr, especially for large
-  // binaries with symbols.
-  char exe_path[MAXPATHLEN];
-  uint32_t size = sizeof(exe_path);
-  if (_NSGetExecutablePath(exe_path, &size) == 0) {
-    char link_path[MAXPATHLEN];
-    if (realpath(exe_path, link_path))
-      return Path(link_path);
-  }
-#elif defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \
-      defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__)
-  char exe_path[PATH_MAX];
-
-  if (getprogpath(exe_path, argv0) != NULL)
-    return Path(exe_path);
-#elif defined(__linux__) || defined(__CYGWIN__)
-  char exe_path[MAXPATHLEN];
-  StringRef aPath("/proc/self/exe");
-  if (sys::fs::exists(aPath)) {
-      // /proc is not always mounted under Linux (chroot for example).
-      ssize_t len = readlink(aPath.str().c_str(), exe_path, sizeof(exe_path));
-      if (len >= 0)
-          return Path(StringRef(exe_path, len));
-  } else {
-      // Fall back to the classical detection.
-      if (getprogpath(exe_path, argv0) != NULL)
-          return Path(exe_path);
-  }
-#elif defined(HAVE_DLFCN_H)
-  // Use dladdr to get executable path if available.
-  Dl_info DLInfo;
-  int err = dladdr(MainAddr, &DLInfo);
-  if (err == 0)
-    return Path();
-
-  // If the filename is a symlink, we need to resolve and return the location of
-  // the actual executable.
-  char link_path[MAXPATHLEN];
-  if (realpath(DLInfo.dli_fname, link_path))
-    return Path(link_path);
-#else
-#error GetMainExecutable is not implemented on this host yet.
-#endif
-  return Path();
-}
-
 bool
 Path::exists() const {
   return 0 == access(path.c_str(), F_OK );

Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=184916&r1=184915&r2=184916&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Wed Jun 26 00:05:37 2013
@@ -200,15 +200,6 @@ Path::GetCurrentDirectory() {
   return Path(pathname);
 }
 
-/// GetMainExecutable - Return the path to the main executable, given the
-/// value of argv[0] from program startup.
-Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {
-  char pathname[MAX_PATH];
-  DWORD ret = ::GetModuleFileNameA(NULL, pathname, MAX_PATH);
-  return ret != MAX_PATH ? Path(pathname) : Path();
-}
-
-
 // FIXME: the above set of functions don't map to Windows very well.
 
 bool





More information about the llvm-commits mailing list