aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorMichael Spencer <bigcheesegs@gmail.com>2024-03-08 23:30:33 -0800
committerGitHub <noreply@github.com>2024-03-08 23:30:33 -0800
commitba13fa2a5d57581bff1a7e9322234af30f4882f6 (patch)
tree9664647feae1b24a0519bf6ff0143c71b2badd2f /llvm/lib/Support/Path.cpp
parentabbf1f18825440338f6e08c94c54d8c8b4fe57d4 (diff)
downloadllvm-ba13fa2a5d57581bff1a7e9322234af30f4882f6.zip
llvm-ba13fa2a5d57581bff1a7e9322234af30f4882f6.tar.gz
llvm-ba13fa2a5d57581bff1a7e9322234af30f4882f6.tar.bz2
[llvm][Support] Add and use errnoAsErrorCode (#84423)
LLVM is inconsistent about how it converts `errno` to `std::error_code`. This can cause problems because values outside of `std::errc` compare differently if one is system and one is generic on POSIX systems. This is even more of a problem on Windows where use of the system category is just wrong, as that is for Windows errors, which have a completely different mapping than POSIX/generic errors. This patch fixes one instance of this mistake in `JSONTransport.cpp`. This patch adds `errnoAsErrorCode()` which makes it so people do not need to think about this issue in the future. It also cleans up a lot of usage of `errno` in LLVM and Clang.
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index acee228..4db9bc8 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -23,7 +23,6 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include <cctype>
-#include <cerrno>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#include <unistd.h>
@@ -1010,7 +1009,7 @@ static std::error_code copy_file_internal(int ReadFD, int WriteFD) {
delete[] Buf;
if (BytesRead < 0 || BytesWritten < 0)
- return std::error_code(errno, std::generic_category());
+ return errnoAsErrorCode();
return std::error_code();
}
@@ -1060,7 +1059,7 @@ ErrorOr<MD5::MD5Result> md5_contents(int FD) {
}
if (BytesRead < 0)
- return std::error_code(errno, std::generic_category());
+ return errnoAsErrorCode();
MD5::MD5Result Result;
Hash.final(Result);
return Result;
@@ -1228,7 +1227,7 @@ TempFile::~TempFile() { assert(Done); }
Error TempFile::discard() {
Done = true;
if (FD != -1 && close(FD) == -1) {
- std::error_code EC = std::error_code(errno, std::generic_category());
+ std::error_code EC = errnoAsErrorCode();
return errorCodeToError(EC);
}
FD = -1;
@@ -1297,10 +1296,8 @@ Error TempFile::keep(const Twine &Name) {
if (!RenameEC)
TmpName = "";
- if (close(FD) == -1) {
- std::error_code EC(errno, std::generic_category());
- return errorCodeToError(EC);
- }
+ if (close(FD) == -1)
+ return errorCodeToError(errnoAsErrorCode());
FD = -1;
return errorCodeToError(RenameEC);
@@ -1319,10 +1316,8 @@ Error TempFile::keep() {
TmpName = "";
- if (close(FD) == -1) {
- std::error_code EC(errno, std::generic_category());
- return errorCodeToError(EC);
- }
+ if (close(FD) == -1)
+ return errorCodeToError(errnoAsErrorCode());
FD = -1;
return Error::success();