revert inadvertent file inclusion in prior commit

Commit 6431c0de16 was not meant to include
changes to fish.cpp.
This commit is contained in:
Kurtis Rader 2016-04-12 19:01:28 -07:00
parent 6431c0de16
commit 9569f51e83

View file

@ -92,34 +92,39 @@ extern "C" {
int _NSGetExecutablePath(char* buf, uint32_t* bufsize); int _NSGetExecutablePath(char* buf, uint32_t* bufsize);
} }
// Return the path to the current executable. This needs to be realpath'd. /* Return the path to the current executable. This needs to be realpath'd. */
static std::string get_executable_path(const char *argv0) static std::string get_executable_path(const char *argv0)
{ {
char buff[PATH_MAX + 1]; char buff[PATH_MAX];
#if __APPLE__ #if __APPLE__
// On OS X use it's proprietary API to get the path to the executable. {
uint32_t buffSize = sizeof buff; /* Returns 0 on success, -1 if the buffer is too small */
if (_NSGetExecutablePath(buff, &buffSize) == 0) return std::string(buff); uint32_t buffSize = sizeof buff;
#else if (0 == _NSGetExecutablePath(buff, &buffSize))
// On non-OS X UNIXes, try /proc directory. return std::string(buff);
ssize_t len;
len = readlink("/proc/self/exe", buff, sizeof buff); // Linux /* Loop until we're big enough */
if (len == -1) { char *mbuff = (char *)malloc(buffSize);
len = readlink("/proc/curproc/file", buff, sizeof buff); // BSD while (0 > _NSGetExecutablePath(mbuff, &buffSize))
if (len == -1) { mbuff = (char *)realloc(mbuff, buffSize);
len = readlink("/proc/self/path/a.out", buff, sizeof buff); // Solaris
} /* Return the string */
} std::string result = mbuff;
if (len > 0) { free(mbuff);
buff[len] = '\0'; return result;
return std::string(buff);
} }
#endif #endif
{
/* On other Unixes, try /proc directory. This might be worth breaking out into macros. */
if (0 < readlink("/proc/self/exe", buff, sizeof buff) || // Linux
0 < readlink("/proc/curproc/file", buff, sizeof buff) || // BSD
0 < readlink("/proc/self/path/a.out", buff, sizeof buff)) // Solaris
{
return std::string(buff);
}
}
// Just return argv0, which probably won't work (i.e. it's not an absolute path or a path /* Just return argv0, which probably won't work (i.e. it's not an absolute path or a path relative to the working directory, but instead something the caller found via $PATH). We'll eventually fall back to the compile time paths. */
// relative to the working directory, but instead something the caller found via $PATH). We'll
// eventually fall back to the compile time paths.
return std::string(argv0 ? argv0 : ""); return std::string(argv0 ? argv0 : "");
} }