aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Support/Unix
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-01-27 22:17:16 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-05-14 11:44:34 +0000
commit04eeddc0aa8e0a417a16eaf9d7d095207f4a8623 (patch)
tree2a5d3b2fe5c852e91531d128d9177754572d5338 /contrib/llvm-project/llvm/lib/Support/Unix
parent0eae32dcef82f6f06de6419a0d623d7def0cc8f6 (diff)
parent6f8fc217eaa12bf657be1c6468ed9938d10168b3 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/Unix')
-rw-r--r--contrib/llvm-project/llvm/lib/Support/Unix/Path.inc25
1 files changed, 19 insertions, 6 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/Unix/Path.inc b/contrib/llvm-project/llvm/lib/Support/Unix/Path.inc
index 1b33e6a88c6a..4697c46d3848 100644
--- a/contrib/llvm-project/llvm/lib/Support/Unix/Path.inc
+++ b/contrib/llvm-project/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();
}