diff --git a/libc/src/signal/linux/CMakeLists.txt b/libc/src/signal/linux/CMakeLists.txt --- a/libc/src/signal/linux/CMakeLists.txt +++ b/libc/src/signal/linux/CMakeLists.txt @@ -15,7 +15,6 @@ ../kill.h DEPENDS libc.include.signal - libc.include.errno libc.src.errno.errno libc.include.sys_syscall libc.src.__support.OSUtil.osutil @@ -100,7 +99,6 @@ ../sigemptyset.h DEPENDS .signal_utils - libc.include.errno libc.include.signal libc.src.errno.errno ) @@ -113,7 +111,6 @@ ../sigaddset.h DEPENDS .signal_utils - libc.include.errno libc.include.signal libc.src.errno.errno ) @@ -137,7 +134,6 @@ ../sigfillset.h DEPENDS .signal_utils - libc.include.errno libc.include.signal libc.src.errno.errno ) @@ -150,7 +146,6 @@ ../sigdelset.h DEPENDS .signal_utils - libc.include.errno libc.include.signal libc.src.errno.errno ) diff --git a/libc/src/signal/linux/kill.cpp b/libc/src/signal/linux/kill.cpp --- a/libc/src/signal/linux/kill.cpp +++ b/libc/src/signal/linux/kill.cpp @@ -9,11 +9,10 @@ #include "src/signal/kill.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. -#include "src/signal/linux/signal_utils.h" - #include "src/__support/common.h" +#include "src/errno/libc_errno.h" +#include "src/signal/linux/signal_utils.h" -#include #include #include // For syscall numbers. @@ -25,7 +24,7 @@ // A negative return value indicates an error with the magnitude of the // value being the error code. if (ret != 0) { - errno = (ret > 0 ? ret : -ret); + libc_errno = (ret > 0 ? ret : -ret); return -1; } diff --git a/libc/src/signal/linux/sigaction.cpp b/libc/src/signal/linux/sigaction.cpp --- a/libc/src/signal/linux/sigaction.cpp +++ b/libc/src/signal/linux/sigaction.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "src/signal/sigaction.h" +#include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" #include "src/__support/common.h" -#include #include namespace __llvm_libc { @@ -38,7 +38,7 @@ SYS_rt_sigaction, signal, libc_new ? &kernel_new : nullptr, libc_old ? &kernel_old : nullptr, sizeof(sigset_t)); if (ret) { - errno = -ret; + libc_errno = -ret; return -1; } diff --git a/libc/src/signal/linux/sigaddset.cpp b/libc/src/signal/linux/sigaddset.cpp --- a/libc/src/signal/linux/sigaddset.cpp +++ b/libc/src/signal/linux/sigaddset.cpp @@ -8,9 +8,9 @@ #include "src/signal/sigaddset.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" -#include #include namespace __llvm_libc { @@ -18,7 +18,7 @@ LLVM_LIBC_FUNCTION(int, sigaddset, (sigset_t * set, int signum)) { if (set != nullptr && add_signal(*set, signum)) return 0; - errno = EINVAL; + libc_errno = EINVAL; return -1; } diff --git a/libc/src/signal/linux/sigaltstack.cpp b/libc/src/signal/linux/sigaltstack.cpp --- a/libc/src/signal/linux/sigaltstack.cpp +++ b/libc/src/signal/linux/sigaltstack.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "src/signal/sigaltstack.h" +#include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" #include "src/__support/common.h" -#include #include #include @@ -25,18 +25,18 @@ // Flags cannot have anything other than SS_DISABLE set. // We do the type-casting to unsigned because the |ss_flags| // field of stack_t is of type "int". - errno = EINVAL; + libc_errno = EINVAL; return -1; } if (ss->ss_size < MINSIGSTKSZ) { - errno = ENOMEM; + libc_errno = ENOMEM; return -1; } } int ret = __llvm_libc::syscall_impl(SYS_sigaltstack, ss, oss); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/signal/linux/sigdelset.cpp b/libc/src/signal/linux/sigdelset.cpp --- a/libc/src/signal/linux/sigdelset.cpp +++ b/libc/src/signal/linux/sigdelset.cpp @@ -8,9 +8,9 @@ #include "src/signal/sigdelset.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" -#include #include namespace __llvm_libc { @@ -18,7 +18,7 @@ LLVM_LIBC_FUNCTION(int, sigdelset, (sigset_t * set, int signum)) { if (set != nullptr && delete_signal(*set, signum)) return 0; - errno = EINVAL; + libc_errno = EINVAL; return -1; } diff --git a/libc/src/signal/linux/sigemptyset.cpp b/libc/src/signal/linux/sigemptyset.cpp --- a/libc/src/signal/linux/sigemptyset.cpp +++ b/libc/src/signal/linux/sigemptyset.cpp @@ -7,18 +7,18 @@ //===----------------------------------------------------------------------===// #include "src/signal/sigemptyset.h" +#include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" #include "src/__support/common.h" -#include #include namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, sigemptyset, (sigset_t * set)) { if (!set) { - errno = EINVAL; + libc_errno = EINVAL; return -1; } *set = empty_set(); diff --git a/libc/src/signal/linux/sigfillset.cpp b/libc/src/signal/linux/sigfillset.cpp --- a/libc/src/signal/linux/sigfillset.cpp +++ b/libc/src/signal/linux/sigfillset.cpp @@ -8,16 +8,16 @@ #include "src/signal/sigfillset.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" -#include #include namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, sigfillset, (sigset_t * set)) { if (!set) { - errno = EINVAL; + libc_errno = EINVAL; return -1; } *set = full_set(); diff --git a/libc/src/signal/linux/sigprocmask.cpp b/libc/src/signal/linux/sigprocmask.cpp --- a/libc/src/signal/linux/sigprocmask.cpp +++ b/libc/src/signal/linux/sigprocmask.cpp @@ -9,11 +9,11 @@ #include "src/signal/sigprocmask.h" #include "include/sys/syscall.h" // For syscall numbers. #include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" #include "src/__support/common.h" -#include #include namespace __llvm_libc { @@ -26,7 +26,7 @@ if (!ret) return 0; - errno = -ret; + libc_errno = -ret; return -1; } diff --git a/libc/src/termios/linux/cfsetispeed.cpp b/libc/src/termios/linux/cfsetispeed.cpp --- a/libc/src/termios/linux/cfsetispeed.cpp +++ b/libc/src/termios/linux/cfsetispeed.cpp @@ -9,8 +9,8 @@ #include "src/termios/cfsetispeed.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" -#include #include namespace __llvm_libc { @@ -19,7 +19,7 @@ constexpr speed_t NOT_SPEED_MASK = ~speed_t(CBAUD); // A speed value is valid only if it is equal to one of the B values. if (t == nullptr || ((speed & NOT_SPEED_MASK) != 0)) { - errno = EINVAL; + libc_errno = EINVAL; return -1; } diff --git a/libc/src/termios/linux/cfsetospeed.cpp b/libc/src/termios/linux/cfsetospeed.cpp --- a/libc/src/termios/linux/cfsetospeed.cpp +++ b/libc/src/termios/linux/cfsetospeed.cpp @@ -7,10 +7,10 @@ //===----------------------------------------------------------------------===// #include "src/termios/cfsetospeed.h" +#include "src/errno/libc_errno.h" #include "src/__support/common.h" -#include #include namespace __llvm_libc { @@ -19,7 +19,7 @@ constexpr speed_t NOT_SPEED_MASK = ~speed_t(CBAUD); // A speed value is valid only if it is equal to one of the B values. if (t == nullptr || ((speed & NOT_SPEED_MASK) != 0)) { - errno = EINVAL; + libc_errno = EINVAL; return -1; } diff --git a/libc/src/termios/linux/tcdrain.cpp b/libc/src/termios/linux/tcdrain.cpp --- a/libc/src/termios/linux/tcdrain.cpp +++ b/libc/src/termios/linux/tcdrain.cpp @@ -10,9 +10,9 @@ #include "src/__support/OSUtil/syscall.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include // Safe to include without the risk of name pollution. -#include #include // For syscall numbers #include diff --git a/libc/src/termios/linux/tcflow.cpp b/libc/src/termios/linux/tcflow.cpp --- a/libc/src/termios/linux/tcflow.cpp +++ b/libc/src/termios/linux/tcflow.cpp @@ -10,9 +10,9 @@ #include "src/__support/OSUtil/syscall.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include // Safe to include without the risk of name pollution. -#include #include // For syscall numbers #include @@ -21,7 +21,7 @@ LLVM_LIBC_FUNCTION(int, tcflow, (int fd, int action)) { long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCXONC, action); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/termios/linux/tcflush.cpp b/libc/src/termios/linux/tcflush.cpp --- a/libc/src/termios/linux/tcflush.cpp +++ b/libc/src/termios/linux/tcflush.cpp @@ -10,9 +10,9 @@ #include "src/__support/OSUtil/syscall.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include // Safe to include without the risk of name pollution. -#include #include // For syscall numbers #include diff --git a/libc/src/termios/linux/tcgetattr.cpp b/libc/src/termios/linux/tcgetattr.cpp --- a/libc/src/termios/linux/tcgetattr.cpp +++ b/libc/src/termios/linux/tcgetattr.cpp @@ -11,9 +11,9 @@ #include "src/__support/OSUtil/syscall.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include // Safe to include without the risk of name pollution. -#include #include // For syscall numbers #include @@ -23,7 +23,7 @@ __llvm_libc::kernel_termios kt; long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCGETS, &kt); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } t->c_iflag = kt.c_iflag; diff --git a/libc/src/termios/linux/tcgetsid.cpp b/libc/src/termios/linux/tcgetsid.cpp --- a/libc/src/termios/linux/tcgetsid.cpp +++ b/libc/src/termios/linux/tcgetsid.cpp @@ -10,9 +10,9 @@ #include "src/__support/OSUtil/syscall.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include // Safe to include without the risk of name pollution. -#include #include // For syscall numbers #include diff --git a/libc/src/termios/linux/tcsendbreak.cpp b/libc/src/termios/linux/tcsendbreak.cpp --- a/libc/src/termios/linux/tcsendbreak.cpp +++ b/libc/src/termios/linux/tcsendbreak.cpp @@ -10,9 +10,9 @@ #include "src/__support/OSUtil/syscall.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include // Safe to include without the risk of name pollution. -#include #include // For syscall numbers #include @@ -24,7 +24,7 @@ // zero. So, we just pass zero to the syscall. long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCSBRK, 0); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/termios/linux/tcsetattr.cpp b/libc/src/termios/linux/tcsetattr.cpp --- a/libc/src/termios/linux/tcsetattr.cpp +++ b/libc/src/termios/linux/tcsetattr.cpp @@ -11,9 +11,9 @@ #include "src/__support/OSUtil/syscall.h" #include "src/__support/common.h" +#include "src/errno/libc_errno.h" #include // Safe to include without the risk of name pollution. -#include #include // For syscall numbers #include @@ -35,7 +35,7 @@ cmd = TCSETSF; break; default: - errno = EINVAL; + libc_errno = EINVAL; return -1; } @@ -53,7 +53,7 @@ long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, cmd, &kt); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/test/src/signal/CMakeLists.txt b/libc/test/src/signal/CMakeLists.txt --- a/libc/test/src/signal/CMakeLists.txt +++ b/libc/test/src/signal/CMakeLists.txt @@ -19,8 +19,6 @@ kill_test.cpp DEPENDS libc.include.signal - libc.include.errno - libc.src.errno.errno libc.src.signal.kill libc.include.sys_syscall libc.src.__support.OSUtil.osutil @@ -48,7 +46,6 @@ SRCS sigprocmask_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.src.signal.raise libc.src.signal.sigaddset @@ -77,7 +74,6 @@ SRCS signal_test.cpp DEPENDS - libc.include.errno libc.include.signal libc.src.errno.errno libc.src.signal.raise @@ -123,9 +119,10 @@ SRCS sigaltstack_test.cpp DEPENDS - libc.include.errno libc.include.signal + libc.src.errno.errno libc.src.signal.raise libc.src.signal.sigaltstack libc.src.signal.sigaction + libc.test.errno_setter_matcher ) diff --git a/libc/test/src/signal/kill_test.cpp b/libc/test/src/signal/kill_test.cpp --- a/libc/test/src/signal/kill_test.cpp +++ b/libc/test/src/signal/kill_test.cpp @@ -13,7 +13,6 @@ #include "test/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" -#include #include using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; diff --git a/libc/test/src/signal/sigaddset_test.cpp b/libc/test/src/signal/sigaddset_test.cpp --- a/libc/test/src/signal/sigaddset_test.cpp +++ b/libc/test/src/signal/sigaddset_test.cpp @@ -6,13 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "include/errno.h" #include "include/signal.h" #include "src/signal/sigaddset.h" #include "test/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" +#include + // This tests invalid inputs and ensures errno is properly set. TEST(LlvmLibcSignalTest, SigaddsetInvalid) { using __llvm_libc::testing::ErrnoSetterMatcher::Fails; diff --git a/libc/test/src/signal/sigaltstack_test.cpp b/libc/test/src/signal/sigaltstack_test.cpp --- a/libc/test/src/signal/sigaltstack_test.cpp +++ b/libc/test/src/signal/sigaltstack_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" #include "src/signal/raise.h" #include "src/signal/sigaction.h" @@ -15,7 +16,6 @@ #include "test/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" -#include #include #include #include @@ -47,7 +47,7 @@ TEST(LlvmLibcSignalTest, SigaltstackRunOnAltStack) { struct sigaction action; - errno = 0; + libc_errno = 0; ASSERT_THAT(__llvm_libc::sigaction(SIGUSR1, nullptr, &action), Succeeds(0)); action.sa_handler = handler; // Indicate that the signal should be delivered on an alternate stack. diff --git a/libc/test/src/signal/sigdelset_test.cpp b/libc/test/src/signal/sigdelset_test.cpp --- a/libc/test/src/signal/sigdelset_test.cpp +++ b/libc/test/src/signal/sigdelset_test.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "include/errno.h" #include "include/signal.h" #include "src/signal/raise.h" #include "src/signal/sigdelset.h" @@ -16,6 +15,8 @@ #include "test/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" +#include + TEST(LlvmLibcSigdelset, Invalid) { using __llvm_libc::testing::ErrnoSetterMatcher::Fails; // Invalid set. diff --git a/libc/test/src/signal/sigfillset_test.cpp b/libc/test/src/signal/sigfillset_test.cpp --- a/libc/test/src/signal/sigfillset_test.cpp +++ b/libc/test/src/signal/sigfillset_test.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "include/errno.h" #include "include/signal.h" #include "src/signal/raise.h" #include "src/signal/sigfillset.h" @@ -15,6 +14,8 @@ #include "test/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" +#include + TEST(LlvmLibcSigfillset, Invalid) { using __llvm_libc::testing::ErrnoSetterMatcher::Fails; EXPECT_THAT(__llvm_libc::sigfillset(nullptr), Fails(EINVAL)); diff --git a/libc/test/src/signal/signal_test.cpp b/libc/test/src/signal/signal_test.cpp --- a/libc/test/src/signal/signal_test.cpp +++ b/libc/test/src/signal/signal_test.cpp @@ -6,9 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "include/errno.h" #include "include/signal.h" -#include "src/errno/llvmlibc_errno.h" +#include "src/errno/libc_errno.h" #include "src/signal/raise.h" #include "src/signal/signal.h" @@ -19,7 +18,7 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; TEST(LlvmLibcSignal, Invalid) { - llvmlibc_errno = 0; + libc_errno = 0; __llvm_libc::sighandler_t valid = +[](int) {}; EXPECT_THAT((void *)__llvm_libc::signal(0, valid), Fails(EINVAL, (void *)SIG_ERR)); diff --git a/libc/test/src/signal/sigprocmask_test.cpp b/libc/test/src/signal/sigprocmask_test.cpp --- a/libc/test/src/signal/sigprocmask_test.cpp +++ b/libc/test/src/signal/sigprocmask_test.cpp @@ -6,9 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "include/errno.h" #include "include/signal.h" -#include "src/errno/llvmlibc_errno.h" +#include "src/errno/libc_errno.h" #include "src/signal/raise.h" #include "src/signal/sigaddset.h" #include "src/signal/sigemptyset.h" @@ -33,7 +32,7 @@ // This tests for invalid input. TEST_F(LlvmLibcSignalTest, SigprocmaskInvalid) { - llvmlibc_errno = 0; + libc_errno = 0; sigset_t valid; // 17 and -4 are out of the range for sigprocmask's how paramater. diff --git a/libc/test/src/termios/CMakeLists.txt b/libc/test/src/termios/CMakeLists.txt --- a/libc/test/src/termios/CMakeLists.txt +++ b/libc/test/src/termios/CMakeLists.txt @@ -7,8 +7,8 @@ SRCS termios_test.cpp DEPENDS - libc.include.errno libc.include.termios + libc.src.errno.errno libc.src.fcntl.open libc.src.termios.cfgetispeed libc.src.termios.cfgetospeed diff --git a/libc/test/src/termios/termios_test.cpp b/libc/test/src/termios/termios_test.cpp --- a/libc/test/src/termios/termios_test.cpp +++ b/libc/test/src/termios/termios_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "src/errno/libc_errno.h" #include "src/fcntl/open.h" #include "src/termios/cfgetispeed.h" #include "src/termios/cfgetospeed.h" @@ -18,7 +19,6 @@ #include "test/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" -#include #include using __llvm_libc::testing::ErrnoSetterMatcher::Fails; @@ -30,35 +30,35 @@ TEST(LlvmLibcTermiosTest, SpeedSmokeTest) { struct termios t; - errno = 0; + libc_errno = 0; ASSERT_THAT(__llvm_libc::cfsetispeed(&t, B50), Succeeds(0)); ASSERT_EQ(__llvm_libc::cfgetispeed(&t), speed_t(B50)); ASSERT_THAT(__llvm_libc::cfsetospeed(&t, B75), Succeeds(0)); ASSERT_EQ(__llvm_libc::cfgetospeed(&t), speed_t(B75)); - errno = 0; + libc_errno = 0; ASSERT_THAT(__llvm_libc::cfsetispeed(&t, ~CBAUD), Fails(EINVAL)); - errno = 0; + libc_errno = 0; ASSERT_THAT(__llvm_libc::cfsetospeed(&t, ~CBAUD), Fails(EINVAL)); } TEST(LlvmLibcTermiosTest, GetAttrSmokeTest) { struct termios t; - errno = 0; + libc_errno = 0; int fd = __llvm_libc::open("/dev/tty", O_RDONLY); if (fd < 0) return; // When /dev/tty is not available, no point continuing. - ASSERT_EQ(errno, 0); + ASSERT_EQ(libc_errno, 0); ASSERT_THAT(__llvm_libc::tcgetattr(fd, &t), Succeeds(0)); ASSERT_EQ(__llvm_libc::close(fd), 0); } TEST(LlvmLibcTermiosTest, TcGetSidSmokeTest) { - errno = 0; + libc_errno = 0; int fd = __llvm_libc::open("/dev/tty", O_RDONLY); if (fd < 0) return; // When /dev/tty is not available, no point continuing. - ASSERT_EQ(errno, 0); + ASSERT_EQ(libc_errno, 0); ASSERT_GT(__llvm_libc::tcgetsid(fd), pid_t(0)); ASSERT_EQ(__llvm_libc::close(fd), 0); }