diff options
Diffstat (limited to 'llvm/lib/Support/Unix/Path.inc')
-rw-r--r-- | llvm/lib/Support/Unix/Path.inc | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index f5cb5895d95d..788460d657fe 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -273,7 +273,7 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) { // the program, and not the eventual binary file. Therefore, call realpath // so this behaves the same on all platforms. #if _POSIX_VERSION >= 200112 || defined(__GLIBC__) - if (char *real_path = realpath(exe_path, NULL)) { + if (char *real_path = realpath(exe_path, nullptr)) { std::string ret = std::string(real_path); free(real_path); return ret; @@ -380,20 +380,22 @@ std::error_code current_path(SmallVectorImpl<char> &result) { return std::error_code(); } - result.reserve(PATH_MAX); + result.resize_for_overwrite(PATH_MAX); while (true) { - if (::getcwd(result.data(), result.capacity()) == nullptr) { + if (::getcwd(result.data(), result.size()) == nullptr) { // See if there was a real error. - if (errno != ENOMEM) + if (errno != ENOMEM) { + result.clear(); return std::error_code(errno, std::generic_category()); + } // Otherwise there just wasn't enough space. - result.reserve(result.capacity() * 2); + result.resize_for_overwrite(result.capacity() * 2); } else break; } - result.set_size(strlen(result.data())); + result.truncate(strlen(result.data())); return std::error_code(); } @@ -870,6 +872,17 @@ void mapped_file_region::unmapImpl() { ::munmap(Mapping, Size); } +void mapped_file_region::dontNeedImpl() { + assert(Mode == mapped_file_region::readonly); +#if defined(__MVS__) || defined(_AIX) + // If we don't have madvise, or it isn't beneficial, treat this as a no-op. + return; +#else + if (Mapping) + ::madvise(Mapping, Size, MADV_DONTNEED); +#endif +} + int mapped_file_region::alignment() { return Process::getPageSizeEstimate(); } |