diff --git a/libc/src/dirent/closedir.cpp b/libc/src/dirent/closedir.cpp --- a/libc/src/dirent/closedir.cpp +++ b/libc/src/dirent/closedir.cpp @@ -10,9 +10,9 @@ #include "src/__support/File/dir.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include -#include namespace __llvm_libc { @@ -20,7 +20,7 @@ auto *d = reinterpret_cast<__llvm_libc::Dir *>(dir); int retval = d->close(); if (retval != 0) { - errno = retval; + libc_errno = retval; return -1; } return 0; diff --git a/libc/src/dirent/opendir.cpp b/libc/src/dirent/opendir.cpp --- a/libc/src/dirent/opendir.cpp +++ b/libc/src/dirent/opendir.cpp @@ -10,16 +10,16 @@ #include "src/__support/File/dir.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include -#include namespace __llvm_libc { LLVM_LIBC_FUNCTION(::DIR *, opendir, (const char *name)) { auto dir = Dir::open(name); if (!dir) { - errno = dir.error(); + libc_errno = dir.error(); return nullptr; } return reinterpret_cast(dir.value()); diff --git a/libc/src/dirent/readdir.cpp b/libc/src/dirent/readdir.cpp --- a/libc/src/dirent/readdir.cpp +++ b/libc/src/dirent/readdir.cpp @@ -10,9 +10,9 @@ #include "src/__support/File/dir.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include -#include namespace __llvm_libc { @@ -20,7 +20,7 @@ auto *d = reinterpret_cast<__llvm_libc::Dir *>(dir); auto dirent_val = d->read(); if (!dirent_val) { - errno = dirent_val.error(); + libc_errno = dirent_val.error(); return nullptr; } return dirent_val; diff --git a/libc/src/fcntl/linux/CMakeLists.txt b/libc/src/fcntl/linux/CMakeLists.txt --- a/libc/src/fcntl/linux/CMakeLists.txt +++ b/libc/src/fcntl/linux/CMakeLists.txt @@ -5,7 +5,6 @@ HDRS ../creat.h DEPENDS - libc.include.errno libc.include.fcntl libc.src.__support.OSUtil.osutil libc.src.errno.errno @@ -18,7 +17,6 @@ HDRS ../open.h DEPENDS - libc.include.errno libc.include.fcntl libc.src.__support.OSUtil.osutil libc.src.errno.errno @@ -31,7 +29,6 @@ HDRS ../openat.h DEPENDS - libc.include.errno libc.include.fcntl libc.src.__support.OSUtil.osutil libc.src.errno.errno diff --git a/libc/src/fcntl/linux/creat.cpp b/libc/src/fcntl/linux/creat.cpp --- a/libc/src/fcntl/linux/creat.cpp +++ b/libc/src/fcntl/linux/creat.cpp @@ -10,8 +10,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" +#include "src/errno/libc_errno.h" -#include #include #include // For syscall numbers. @@ -29,7 +29,7 @@ if (fd > 0) return fd; - errno = -fd; + libc_errno = -fd; return -1; } diff --git a/libc/src/fcntl/linux/open.cpp b/libc/src/fcntl/linux/open.cpp --- a/libc/src/fcntl/linux/open.cpp +++ b/libc/src/fcntl/linux/open.cpp @@ -10,8 +10,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" +#include "src/errno/libc_errno.h" -#include #include #include #include // For syscall numbers. @@ -38,7 +38,7 @@ if (fd > 0) return fd; - errno = -fd; + libc_errno = -fd; return -1; } diff --git a/libc/src/fcntl/linux/openat.cpp b/libc/src/fcntl/linux/openat.cpp --- a/libc/src/fcntl/linux/openat.cpp +++ b/libc/src/fcntl/linux/openat.cpp @@ -10,8 +10,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" +#include "src/errno/libc_errno.h" -#include #include #include #include // For syscall numbers. @@ -33,7 +33,7 @@ if (fd > 0) return fd; - errno = -fd; + libc_errno = -fd; return -1; } diff --git a/libc/src/inttypes/CMakeLists.txt b/libc/src/inttypes/CMakeLists.txt --- a/libc/src/inttypes/CMakeLists.txt +++ b/libc/src/inttypes/CMakeLists.txt @@ -6,6 +6,7 @@ strtoimax.h DEPENDS libc.src.__support.str_to_integer + libc.src.errno.errno ) add_entrypoint_object( @@ -16,6 +17,7 @@ strtoumax.h DEPENDS libc.src.__support.str_to_integer + libc.src.errno.errno ) add_entrypoint_object( diff --git a/libc/src/inttypes/strtoimax.cpp b/libc/src/inttypes/strtoimax.cpp --- a/libc/src/inttypes/strtoimax.cpp +++ b/libc/src/inttypes/strtoimax.cpp @@ -9,6 +9,7 @@ #include "src/inttypes/strtoimax.h" #include "src/__support/common.h" #include "src/__support/str_to_integer.h" +#include "src/errno/libc_errno.h" namespace __llvm_libc { @@ -17,7 +18,7 @@ int base)) { auto result = internal::strtointeger(str, base); if (result.has_error()) - errno = result.error; + libc_errno = result.error; if (str_end != nullptr) *str_end = const_cast(str + result.parsed_len); diff --git a/libc/src/inttypes/strtoumax.cpp b/libc/src/inttypes/strtoumax.cpp --- a/libc/src/inttypes/strtoumax.cpp +++ b/libc/src/inttypes/strtoumax.cpp @@ -9,6 +9,7 @@ #include "src/inttypes/strtoumax.h" #include "src/__support/common.h" #include "src/__support/str_to_integer.h" +#include "src/errno/libc_errno.h" namespace __llvm_libc { @@ -17,7 +18,7 @@ int base)) { auto result = internal::strtointeger(str, base); if (result.has_error()) - errno = result.error; + libc_errno = result.error; if (str_end != nullptr) *str_end = const_cast(str + result.parsed_len); diff --git a/libc/src/sched/linux/CMakeLists.txt b/libc/src/sched/linux/CMakeLists.txt --- a/libc/src/sched/linux/CMakeLists.txt +++ b/libc/src/sched/linux/CMakeLists.txt @@ -5,7 +5,6 @@ HDRS ../sched_getaffinity.h DEPENDS - libc.include.errno libc.include.sched libc.src.__support.OSUtil.osutil libc.src.errno.errno @@ -18,7 +17,6 @@ HDRS ../sched_setaffinity.h DEPENDS - libc.include.errno libc.include.sched libc.src.__support.OSUtil.osutil libc.src.errno.errno diff --git a/libc/src/sched/linux/sched_getaffinity.cpp b/libc/src/sched/linux/sched_getaffinity.cpp --- a/libc/src/sched/linux/sched_getaffinity.cpp +++ b/libc/src/sched/linux/sched_getaffinity.cpp @@ -10,8 +10,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" +#include "src/errno/libc_errno.h" -#include #include #include #include // For syscall numbers. @@ -23,7 +23,7 @@ long ret = __llvm_libc::syscall_impl(SYS_sched_getaffinity, tid, cpuset_size, mask); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } if (size_t(ret) < cpuset_size) { diff --git a/libc/src/sched/linux/sched_setaffinity.cpp b/libc/src/sched/linux/sched_setaffinity.cpp --- a/libc/src/sched/linux/sched_setaffinity.cpp +++ b/libc/src/sched/linux/sched_setaffinity.cpp @@ -10,8 +10,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" +#include "src/errno/libc_errno.h" -#include #include #include // For syscall numbers. @@ -22,7 +22,7 @@ long ret = __llvm_libc::syscall_impl(SYS_sched_setaffinity, tid, cpuset_size, mask); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/test/src/dirent/CMakeLists.txt b/libc/test/src/dirent/CMakeLists.txt --- a/libc/test/src/dirent/CMakeLists.txt +++ b/libc/test/src/dirent/CMakeLists.txt @@ -8,11 +8,11 @@ SRCS dirent_test.cpp DEPENDS - libc.include.dirent libc.src.__support.CPP.string_view libc.src.dirent.closedir libc.src.dirent.dirfd libc.src.dirent.opendir libc.src.dirent.readdir + libc.src.errno.errno ) diff --git a/libc/test/src/dirent/dirent_test.cpp b/libc/test/src/dirent/dirent_test.cpp --- a/libc/test/src/dirent/dirent_test.cpp +++ b/libc/test/src/dirent/dirent_test.cpp @@ -11,11 +11,11 @@ #include "src/dirent/dirfd.h" #include "src/dirent/opendir.h" #include "src/dirent/readdir.h" +#include "src/errno/libc_errno.h" #include "test/UnitTest/Test.h" #include -#include using string_view = __llvm_libc::cpp::string_view; @@ -44,7 +44,7 @@ } // Verify that we don't break out of the above loop in error. - ASSERT_EQ(errno, 0); + ASSERT_EQ(libc_errno, 0); ASSERT_TRUE(file1 != nullptr); ASSERT_TRUE(file2 != nullptr); @@ -55,17 +55,17 @@ } TEST(LlvmLibcDirentTest, OpenNonExistentDir) { - errno = 0; + libc_errno = 0; ::DIR *dir = __llvm_libc::opendir("___xyz123__.non_existent__"); ASSERT_TRUE(dir == nullptr); - ASSERT_EQ(errno, ENOENT); - errno = 0; + ASSERT_EQ(libc_errno, ENOENT); + libc_errno = 0; } TEST(LlvmLibcDirentTest, OpenFile) { - errno = 0; + libc_errno = 0; ::DIR *dir = __llvm_libc::opendir("testdata/file1.txt"); ASSERT_TRUE(dir == nullptr); - ASSERT_EQ(errno, ENOTDIR); - errno = 0; + ASSERT_EQ(libc_errno, ENOTDIR); + libc_errno = 0; } diff --git a/libc/test/src/fcntl/CMakeLists.txt b/libc/test/src/fcntl/CMakeLists.txt --- a/libc/test/src/fcntl/CMakeLists.txt +++ b/libc/test/src/fcntl/CMakeLists.txt @@ -9,8 +9,8 @@ SRCS creat_test.cpp DEPENDS - libc.include.errno libc.include.fcntl + libc.src.errno.errno libc.src.fcntl.creat libc.src.fcntl.open libc.src.unistd.close @@ -24,8 +24,8 @@ SRCS openat_test.cpp DEPENDS - libc.include.errno libc.include.fcntl + libc.src.errno.errno libc.src.fcntl.open libc.src.fcntl.openat libc.src.unistd.close diff --git a/libc/test/src/fcntl/creat_test.cpp b/libc/test/src/fcntl/creat_test.cpp --- a/libc/test/src/fcntl/creat_test.cpp +++ b/libc/test/src/fcntl/creat_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "src/errno/libc_errno.h" #include "src/fcntl/creat.h" #include "src/fcntl/open.h" #include "src/unistd/close.h" @@ -13,18 +14,16 @@ #include "test/UnitTest/Test.h" #include "utils/testutils/FDReader.h" -#include - TEST(LlvmLibcCreatTest, CreatAndOpen) { using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; constexpr const char *TEST_FILE = "testdata/creat.test"; int fd = __llvm_libc::creat(TEST_FILE, S_IRWXU); - ASSERT_EQ(errno, 0); + ASSERT_EQ(libc_errno, 0); ASSERT_GT(fd, 0); ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0)); fd = __llvm_libc::open(TEST_FILE, O_RDONLY); - ASSERT_EQ(errno, 0); + ASSERT_EQ(libc_errno, 0); ASSERT_GT(fd, 0); ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0)); diff --git a/libc/test/src/fcntl/openat_test.cpp b/libc/test/src/fcntl/openat_test.cpp --- a/libc/test/src/fcntl/openat_test.cpp +++ b/libc/test/src/fcntl/openat_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "src/errno/libc_errno.h" #include "src/fcntl/open.h" #include "src/fcntl/openat.h" #include "src/unistd/close.h" @@ -14,7 +15,6 @@ #include "test/UnitTest/Test.h" #include "utils/testutils/FDReader.h" -#include #include TEST(LlvmLibcUniStd, OpenAndReadTest) { @@ -22,13 +22,13 @@ constexpr const char *TEST_DIR = "testdata"; constexpr const char *TEST_FILE = "openat.test"; int dir_fd = __llvm_libc::open(TEST_DIR, O_DIRECTORY); - ASSERT_EQ(errno, 0); + ASSERT_EQ(libc_errno, 0); ASSERT_GT(dir_fd, 0); constexpr const char TEST_MSG[] = "openat test"; constexpr int TEST_MSG_SIZE = sizeof(TEST_MSG) - 1; int read_fd = __llvm_libc::openat(dir_fd, TEST_FILE, O_RDONLY); - ASSERT_EQ(errno, 0); + ASSERT_EQ(libc_errno, 0); ASSERT_GT(read_fd, 0); char read_buf[TEST_MSG_SIZE]; ASSERT_THAT(__llvm_libc::read(read_fd, read_buf, TEST_MSG_SIZE), diff --git a/libc/test/src/sched/CMakeLists.txt b/libc/test/src/sched/CMakeLists.txt --- a/libc/test/src/sched/CMakeLists.txt +++ b/libc/test/src/sched/CMakeLists.txt @@ -7,10 +7,10 @@ SRCS affinity_test.cpp DEPENDS - libc.include.errno libc.include.sched libc.include.sys_syscall libc.src.__support.OSUtil.osutil + libc.src.errno.errno libc.src.sched.sched_getaffinity libc.src.sched.sched_setaffinity libc.test.errno_setter_matcher @@ -23,10 +23,10 @@ SRCS cpu_count_test.cpp DEPENDS - libc.include.errno libc.include.sched libc.include.sys_syscall libc.src.__support.OSUtil.osutil + libc.src.errno.errno libc.src.sched.sched_getaffinity libc.src.sched.__sched_getcpucount libc.test.errno_setter_matcher diff --git a/libc/test/src/sched/affinity_test.cpp b/libc/test/src/sched/affinity_test.cpp --- a/libc/test/src/sched/affinity_test.cpp +++ b/libc/test/src/sched/affinity_test.cpp @@ -7,17 +7,17 @@ //===----------------------------------------------------------------------===// #include "src/__support/OSUtil/syscall.h" +#include "src/errno/libc_errno.h" #include "src/sched/sched_getaffinity.h" #include "src/sched/sched_setaffinity.h" #include "test/ErrnoSetterMatcher.h" -#include #include #include TEST(LlvmLibcSchedAffinityTest, SmokeTest) { cpu_set_t mask; - errno = 0; + libc_errno = 0; using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; pid_t tid = __llvm_libc::syscall_impl(SYS_gettid); ASSERT_GT(tid, pid_t(0)); @@ -32,13 +32,13 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Fails; pid_t tid = __llvm_libc::syscall_impl(SYS_gettid); - errno = 0; + libc_errno = 0; ASSERT_THAT(__llvm_libc::sched_getaffinity(tid, sizeof(cpu_set_t), nullptr), Fails(EFAULT)); - errno = 0; + libc_errno = 0; ASSERT_THAT(__llvm_libc::sched_setaffinity(tid, sizeof(cpu_set_t), nullptr), Fails(EFAULT)); - errno = 0; + libc_errno = 0; } diff --git a/libc/test/src/sched/cpu_count_test.cpp b/libc/test/src/sched/cpu_count_test.cpp --- a/libc/test/src/sched/cpu_count_test.cpp +++ b/libc/test/src/sched/cpu_count_test.cpp @@ -7,17 +7,17 @@ //===----------------------------------------------------------------------===// #include "src/__support/OSUtil/syscall.h" +#include "src/errno/libc_errno.h" #include "src/sched/sched_getaffinity.h" #include "src/sched/sched_getcpucount.h" #include "test/ErrnoSetterMatcher.h" -#include #include #include TEST(LlvmLibcSchedAffinityTest, SmokeTest) { cpu_set_t mask; - errno = 0; + libc_errno = 0; using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; pid_t tid = __llvm_libc::syscall_impl(SYS_gettid); ASSERT_GT(tid, pid_t(0));