forked from OSchip/llvm-project
Prefer PATH_MAX to MAXPATHLEN
The former is part of POSIX and requires less heavy headers. They are practically functionally equivalent.
This commit is contained in:
parent
03dd205c15
commit
4e45ef4d77
|
@ -59,7 +59,6 @@ extern char **environ;
|
|||
// For GNU Hurd
|
||||
#if defined(__GNU__) && !defined(PATH_MAX)
|
||||
# define PATH_MAX 4096
|
||||
# define MAXPATHLEN 4096
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -184,10 +183,10 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
|
|||
// 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];
|
||||
char exe_path[PATH_MAX];
|
||||
uint32_t size = sizeof(exe_path);
|
||||
if (_NSGetExecutablePath(exe_path, &size) == 0) {
|
||||
char link_path[MAXPATHLEN];
|
||||
char link_path[PATH_MAX];
|
||||
if (realpath(exe_path, link_path))
|
||||
return link_path;
|
||||
}
|
||||
|
@ -239,7 +238,7 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
|
|||
if (getprogpath(exe_path, argv0) != NULL)
|
||||
return exe_path;
|
||||
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__gnu_hurd__)
|
||||
char exe_path[MAXPATHLEN];
|
||||
char exe_path[PATH_MAX];
|
||||
const char *aPath = "/proc/self/exe";
|
||||
if (sys::fs::exists(aPath)) {
|
||||
// /proc is not always mounted under Linux (chroot for example).
|
||||
|
@ -263,7 +262,7 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
|
|||
return ret;
|
||||
}
|
||||
#else
|
||||
char real_path[MAXPATHLEN];
|
||||
char real_path[PATH_MAX];
|
||||
if (realpath(exe_path, real_path))
|
||||
return std::string(real_path);
|
||||
#endif
|
||||
|
@ -280,7 +279,7 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
|
|||
|
||||
// If the filename is a symlink, we need to resolve and return the location of
|
||||
// the actual executable.
|
||||
char link_path[MAXPATHLEN];
|
||||
char link_path[PATH_MAX];
|
||||
if (realpath(DLInfo.dli_fname, link_path))
|
||||
return link_path;
|
||||
#else
|
||||
|
@ -330,12 +329,7 @@ std::error_code current_path(SmallVectorImpl<char> &result) {
|
|||
return std::error_code();
|
||||
}
|
||||
|
||||
#ifdef MAXPATHLEN
|
||||
result.reserve(MAXPATHLEN);
|
||||
#else
|
||||
// For GNU Hurd
|
||||
result.reserve(1024);
|
||||
#endif
|
||||
result.reserve(PATH_MAX);
|
||||
|
||||
while (true) {
|
||||
if (::getcwd(result.data(), result.capacity()) == nullptr) {
|
||||
|
@ -998,7 +992,7 @@ std::error_code openFileForRead(const Twine &Name, int &ResultFD,
|
|||
#if defined(F_GETPATH)
|
||||
// When F_GETPATH is availble, it is the quickest way to get
|
||||
// the real path name.
|
||||
char Buffer[MAXPATHLEN];
|
||||
char Buffer[PATH_MAX];
|
||||
if (::fcntl(ResultFD, F_GETPATH, Buffer) != -1)
|
||||
RealPath->append(Buffer, Buffer + strlen(Buffer));
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue