aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Support/Unix
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2022-03-27 18:01:38 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2022-03-27 18:01:38 +0000
commit30ed48b0a50a062415addcac216371a55e1f6a66 (patch)
tree0c02f7eb393d8901c363ebde5b03cd8412af1f9d /contrib/llvm-project/llvm/lib/Support/Unix
parentef88adc5273dea4139fc5693cc34508d492979e7 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/Unix')
-rw-r--r--contrib/llvm-project/llvm/lib/Support/Unix/Path.inc14
1 files changed, 13 insertions, 1 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/Unix/Path.inc b/contrib/llvm-project/llvm/lib/Support/Unix/Path.inc
index c37b3a54644a..8c2af5ee0f8d 100644
--- a/contrib/llvm-project/llvm/lib/Support/Unix/Path.inc
+++ b/contrib/llvm-project/llvm/lib/Support/Unix/Path.inc
@@ -930,7 +930,15 @@ ErrorOr<basic_file_status> directory_entry::status() const {
return s;
}
-#if !defined(F_GETPATH)
+//
+// FreeBSD optionally provides /proc/self/fd, but it is incompatible with
+// Linux. The thing to use is realpath.
+//
+#if !defined(__FreeBSD__)
+#define TRY_PROC_SELF_FD
+#endif
+
+#if !defined(F_GETPATH) && defined(TRY_PROC_SELF_FD)
static bool hasProcSelfFD() {
// If we have a /proc filesystem mounted, we can quickly establish the
// real name of the file with readlink
@@ -1117,6 +1125,7 @@ std::error_code openFileForRead(const Twine &Name, int &ResultFD,
RealPath->append(Buffer, Buffer + strlen(Buffer));
#else
char Buffer[PATH_MAX];
+#if defined(TRY_PROC_SELF_FD)
if (hasProcSelfFD()) {
char ProcPath[64];
snprintf(ProcPath, sizeof(ProcPath), "/proc/self/fd/%d", ResultFD);
@@ -1124,14 +1133,17 @@ std::error_code openFileForRead(const Twine &Name, int &ResultFD,
if (CharCount > 0)
RealPath->append(Buffer, Buffer + CharCount);
} else {
+#endif
SmallString<128> Storage;
StringRef P = Name.toNullTerminatedStringRef(Storage);
// Use ::realpath to get the real path name
if (::realpath(P.begin(), Buffer) != nullptr)
RealPath->append(Buffer, Buffer + strlen(Buffer));
+#if defined(TRY_PROC_SELF_FD)
}
#endif
+#endif
return std::error_code();
}