diff --git a/libc/src/sys/mman/linux/madvise.cpp b/libc/src/sys/mman/linux/madvise.cpp index 3e6e574d1f14..5131b38b08d5 100644 --- a/libc/src/sys/mman/linux/madvise.cpp +++ b/libc/src/sys/mman/linux/madvise.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For syscall numbers. namespace __llvm_libc { @@ -25,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, madvise, (void *addr, size_t size, int advice)) { // A negative return value indicates an error with the magnitude of the // value being the error code. if (ret_val < 0) { - errno = -ret_val; + libc_errno = -ret_val; return -1; } diff --git a/libc/src/sys/mman/linux/mmap.cpp b/libc/src/sys/mman/linux/mmap.cpp index f08877e466c1..daf29f4204a0 100644 --- a/libc/src/sys/mman/linux/mmap.cpp +++ b/libc/src/sys/mman/linux/mmap.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For EXEC_PAGESIZE. #include // For syscall numbers. @@ -53,7 +53,7 @@ LLVM_LIBC_FUNCTION(void *, mmap, // return value corresponding to a location in the last page is an error // value. if (ret_val < 0 && ret_val > -EXEC_PAGESIZE) { - errno = -ret_val; + libc_errno = -ret_val; return MAP_FAILED; } diff --git a/libc/src/sys/mman/linux/mprotect.cpp b/libc/src/sys/mman/linux/mprotect.cpp index 6ea35c279d54..08a5f6e51ed5 100644 --- a/libc/src/sys/mman/linux/mprotect.cpp +++ b/libc/src/sys/mman/linux/mprotect.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For syscall numbers. namespace __llvm_libc { @@ -25,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, mprotect, (void *addr, size_t size, int prot)) { // A negative return value indicates an error with the magnitude of the // value being the error code. if (ret_val < 0) { - errno = -ret_val; + libc_errno = -ret_val; return -1; } diff --git a/libc/src/sys/mman/linux/munmap.cpp b/libc/src/sys/mman/linux/munmap.cpp index 3be5a8977299..2a34a86edc37 100644 --- a/libc/src/sys/mman/linux/munmap.cpp +++ b/libc/src/sys/mman/linux/munmap.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For syscall numbers. namespace __llvm_libc { @@ -25,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, munmap, (void *addr, size_t size)) { // A negative return value indicates an error with the magnitude of the // value being the error code. if (ret_val < 0) { - errno = -ret_val; + libc_errno = -ret_val; return -1; } diff --git a/libc/src/sys/random/linux/getrandom.cpp b/libc/src/sys/random/linux/getrandom.cpp index e9c33da3d294..58a72fc91852 100644 --- a/libc/src/sys/random/linux/getrandom.cpp +++ b/libc/src/sys/random/linux/getrandom.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For syscall numbers. namespace __llvm_libc { @@ -20,7 +20,7 @@ LLVM_LIBC_FUNCTION(ssize_t, getrandom, (void *buf, size_t buflen, unsigned int flags)) { long ret = __llvm_libc::syscall_impl(SYS_getrandom, buf, buflen, flags); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/sys/resource/linux/getrlimit.cpp b/libc/src/sys/resource/linux/getrlimit.cpp index 613c1a78e670..25a84435658e 100644 --- a/libc/src/sys/resource/linux/getrlimit.cpp +++ b/libc/src/sys/resource/linux/getrlimit.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For struct rlimit #include // For syscall numbers. @@ -20,7 +20,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, getrlimit, (int res, struct rlimit *limits)) { long ret = __llvm_libc::syscall_impl(SYS_prlimit64, 0, res, nullptr, limits); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/sys/resource/linux/setrlimit.cpp b/libc/src/sys/resource/linux/setrlimit.cpp index b0c1ea52e783..33c08a74deff 100644 --- a/libc/src/sys/resource/linux/setrlimit.cpp +++ b/libc/src/sys/resource/linux/setrlimit.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For struct rlimit #include // For syscall numbers. @@ -20,7 +20,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, setrlimit, (int res, const struct rlimit *limits)) { long ret = __llvm_libc::syscall_impl(SYS_prlimit64, 0, res, limits, nullptr); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/sys/select/linux/select.cpp b/libc/src/sys/select/linux/select.cpp index ba81f9ba188c..e77aafeb9029 100644 --- a/libc/src/sys/select/linux/select.cpp +++ b/libc/src/sys/select/linux/select.cpp @@ -12,7 +12,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include #include // For size_t #include @@ -56,7 +56,7 @@ LLVM_LIBC_FUNCTION(int, select, long ret = __llvm_libc::syscall_impl(SYS_pselect6, nfds, read_set, write_set, error_set, &ts, &pss); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/sys/sendfile/linux/sendfile.cpp b/libc/src/sys/sendfile/linux/sendfile.cpp index 1f8a2c4421b3..d54100dfe57d 100644 --- a/libc/src/sys/sendfile/linux/sendfile.cpp +++ b/libc/src/sys/sendfile/linux/sendfile.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include #include // For syscall numbers. @@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(ssize_t, sendfile, long ret = __llvm_libc::syscall_impl(SYS_sendfile, in_fd, out_fd, offset, count); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/sys/stat/linux/chmod.cpp b/libc/src/sys/stat/linux/chmod.cpp index 1b8c6ee19b58..9962146c6945 100644 --- a/libc/src/sys/stat/linux/chmod.cpp +++ b/libc/src/sys/stat/linux/chmod.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include #include #include // For syscall numbers. @@ -28,7 +28,7 @@ LLVM_LIBC_FUNCTION(int, chmod, (const char *path, mode_t mode)) { #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/sys/stat/linux/fchmod.cpp b/libc/src/sys/stat/linux/fchmod.cpp index c6ce8d9acb8f..4c9a7a645f61 100644 --- a/libc/src/sys/stat/linux/fchmod.cpp +++ b/libc/src/sys/stat/linux/fchmod.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include #include #include // For syscall numbers. @@ -21,7 +21,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fchmod, (int fd, mode_t mode)) { long ret = __llvm_libc::syscall_impl(SYS_fchmod, fd, mode); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/sys/stat/linux/fchmodat.cpp b/libc/src/sys/stat/linux/fchmodat.cpp index 82a9a831eef5..51ea63a0ca39 100644 --- a/libc/src/sys/stat/linux/fchmodat.cpp +++ b/libc/src/sys/stat/linux/fchmodat.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include #include // For syscall numbers. @@ -21,7 +21,7 @@ LLVM_LIBC_FUNCTION(int, fchmodat, (int dirfd, const char *path, mode_t mode, int flags)) { long ret = __llvm_libc::syscall_impl(SYS_fchmodat, dirfd, path, mode, flags); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/sys/stat/linux/mkdir.cpp b/libc/src/sys/stat/linux/mkdir.cpp index 404ea0f7be41..0074538f94ce 100644 --- a/libc/src/sys/stat/linux/mkdir.cpp +++ b/libc/src/sys/stat/linux/mkdir.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include #include #include // For syscall numbers. @@ -28,7 +28,7 @@ LLVM_LIBC_FUNCTION(int, mkdir, (const char *path, mode_t mode)) { #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/sys/stat/linux/mkdirat.cpp b/libc/src/sys/stat/linux/mkdirat.cpp index 0ab146942f5a..71bc1cef8715 100644 --- a/libc/src/sys/stat/linux/mkdirat.cpp +++ b/libc/src/sys/stat/linux/mkdirat.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include #include // For syscall numbers. @@ -25,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, mkdirat, (int dfd, const char *path, mode_t mode)) { #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/sys/utsname/linux/uname.cpp b/libc/src/sys/utsname/linux/uname.cpp index 86724b3ffcc3..5599dd36e4a1 100644 --- a/libc/src/sys/utsname/linux/uname.cpp +++ b/libc/src/sys/utsname/linux/uname.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For syscall numbers. #include @@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(int, uname, (struct utsname * name)) { if (ret >= 0) return 1; - errno = -ret; + libc_errno = -ret; return -1; } diff --git a/libc/src/sys/wait/linux/CMakeLists.txt b/libc/src/sys/wait/linux/CMakeLists.txt index 89f10ec68579..49517ced71d1 100644 --- a/libc/src/sys/wait/linux/CMakeLists.txt +++ b/libc/src/sys/wait/linux/CMakeLists.txt @@ -5,7 +5,6 @@ add_entrypoint_object( HDRS ../wait.h DEPENDS - libc.include.errno libc.include.sys_wait libc.include.sys_syscall libc.src.__support.OSUtil.osutil @@ -19,7 +18,6 @@ add_entrypoint_object( HDRS ../wait4.h DEPENDS - libc.include.errno libc.include.sys_wait libc.include.sys_syscall libc.src.__support.OSUtil.osutil @@ -33,7 +31,6 @@ add_entrypoint_object( HDRS ../waitpid.h DEPENDS - libc.include.errno libc.include.sys_wait libc.include.sys_syscall libc.src.__support.OSUtil.osutil diff --git a/libc/src/sys/wait/linux/wait.cpp b/libc/src/sys/wait/linux/wait.cpp index 91300f2f2f46..497d3e1754df 100644 --- a/libc/src/sys/wait/linux/wait.cpp +++ b/libc/src/sys/wait/linux/wait.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For syscall numbers. #include @@ -24,7 +24,7 @@ LLVM_LIBC_FUNCTION(pid_t, wait, (int *wait_status)) { pid_t pid = __llvm_libc::syscall_impl(SYS_wait4, -1, wait_status, 0, 0); if (pid < 0) { // Error case, a child process was not created. - errno = -pid; + libc_errno = -pid; return -1; } diff --git a/libc/src/sys/wait/linux/wait4.cpp b/libc/src/sys/wait/linux/wait4.cpp index f52346cc47ad..157aa991d66e 100644 --- a/libc/src/sys/wait/linux/wait4.cpp +++ b/libc/src/sys/wait/linux/wait4.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For syscall numbers. #include @@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(pid_t, wait4, struct rusage *usage)) { pid = __llvm_libc::syscall_impl(SYS_wait4, pid, wait_status, options, usage); if (pid < 0) { - errno = -pid; + libc_errno = -pid; return -1; } return pid; diff --git a/libc/src/sys/wait/linux/waitpid.cpp b/libc/src/sys/wait/linux/waitpid.cpp index f5e5d2b1bc1f..9b9538aef77d 100644 --- a/libc/src/sys/wait/linux/waitpid.cpp +++ b/libc/src/sys/wait/linux/waitpid.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For syscall numbers. #include @@ -20,7 +20,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(pid_t, waitpid, (pid_t pid, int *wait_status, int options)) { pid = __llvm_libc::syscall_impl(SYS_wait4, pid, wait_status, options, 0); if (pid < 0) { - errno = -pid; + libc_errno = -pid; return -1; } return pid; diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt index e5ea13e77655..2507e1e9a938 100644 --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -97,7 +97,6 @@ add_entrypoint_object( HDRS ../fork.h DEPENDS - libc.include.errno libc.include.unistd libc.include.sys_syscall libc.src.__support.threads.fork_callbacks @@ -113,7 +112,6 @@ add_entrypoint_object( HDRS ../execv.h DEPENDS - libc.include.errno libc.include.sys_syscall libc.src.__support.OSUtil.osutil libc.src.errno.errno @@ -127,7 +125,6 @@ add_entrypoint_object( HDRS ../execve.h DEPENDS - libc.include.errno libc.include.sys_syscall libc.src.__support.OSUtil.osutil libc.src.errno.errno @@ -166,7 +163,6 @@ add_entrypoint_object( HDRS ../getcwd.h DEPENDS - libc.include.errno libc.include.stdlib libc.include.unistd libc.include.sys_syscall @@ -230,7 +226,6 @@ add_entrypoint_object( ../isatty.h DEPENDS libc.include.unistd - libc.include.errno libc.include.sys_syscall libc.src.__support.OSUtil.osutil libc.src.errno.errno diff --git a/libc/src/unistd/linux/access.cpp b/libc/src/unistd/linux/access.cpp index 1862faaeefdd..d7ebd9707498 100644 --- a/libc/src/unistd/linux/access.cpp +++ b/libc/src/unistd/linux/access.cpp @@ -11,8 +11,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include #include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -27,7 +27,7 @@ LLVM_LIBC_FUNCTION(int, access, (const char *path, int mode)) { #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/unistd/linux/chdir.cpp b/libc/src/unistd/linux/chdir.cpp index 9a8bc1d93f08..f30835b063c9 100644 --- a/libc/src/unistd/linux/chdir.cpp +++ b/libc/src/unistd/linux/chdir.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, chdir, (const char *path)) { long ret = __llvm_libc::syscall_impl(SYS_chdir, path); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/unistd/linux/close.cpp b/libc/src/unistd/linux/close.cpp index 850222e8b7ec..07850609b696 100644 --- a/libc/src/unistd/linux/close.cpp +++ b/libc/src/unistd/linux/close.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, close, (int fd)) { long ret = __llvm_libc::syscall_impl(SYS_close, fd); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/dup.cpp b/libc/src/unistd/linux/dup.cpp index 9e537dc88bb4..63a4ed445edd 100644 --- a/libc/src/unistd/linux/dup.cpp +++ b/libc/src/unistd/linux/dup.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, dup, (int fd)) { long ret = __llvm_libc::syscall_impl(SYS_dup, fd); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/dup2.cpp b/libc/src/unistd/linux/dup2.cpp index 760adc6b7bb6..229f2caa8a52 100644 --- a/libc/src/unistd/linux/dup2.cpp +++ b/libc/src/unistd/linux/dup2.cpp @@ -11,8 +11,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include #include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -30,7 +30,7 @@ LLVM_LIBC_FUNCTION(int, dup2, (int oldfd, int newfd)) { long ret = __llvm_libc::syscall_impl(SYS_fcntl, oldfd, F_GETFD); if (ret >= 0) return oldfd; - errno = -ret; + libc_errno = -ret; return -1; } long ret = __llvm_libc::syscall_impl(SYS_dup3, oldfd, newfd, 0); @@ -38,7 +38,7 @@ LLVM_LIBC_FUNCTION(int, dup2, (int oldfd, int newfd)) { #error "SYS_dup2 and SYS_dup3 not available for the target." #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/dup3.cpp b/libc/src/unistd/linux/dup3.cpp index 8f6930900f0f..c688fb709061 100644 --- a/libc/src/unistd/linux/dup3.cpp +++ b/libc/src/unistd/linux/dup3.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -21,7 +21,7 @@ LLVM_LIBC_FUNCTION(int, dup3, (int oldfd, int newfd, int flags)) { long ret = __llvm_libc::syscall_impl(SYS_dup3, oldfd, newfd, flags); if (ret >= 0) return ret; - errno = -ret; + libc_errno = -ret; return -1; } diff --git a/libc/src/unistd/linux/execv.cpp b/libc/src/unistd/linux/execv.cpp index 8eef5745ad4a..89d1c7504dfe 100644 --- a/libc/src/unistd/linux/execv.cpp +++ b/libc/src/unistd/linux/execv.cpp @@ -12,7 +12,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -21,7 +21,7 @@ LLVM_LIBC_FUNCTION(int, execv, (const char *path, char *const argv[])) { long ret = __llvm_libc::syscall_impl(SYS_execve, path, argv, __llvm_libc::environ); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } diff --git a/libc/src/unistd/linux/execve.cpp b/libc/src/unistd/linux/execve.cpp index d490f662c1a6..995e3fe4b7f7 100644 --- a/libc/src/unistd/linux/execve.cpp +++ b/libc/src/unistd/linux/execve.cpp @@ -12,7 +12,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -21,7 +21,7 @@ LLVM_LIBC_FUNCTION(int, execve, (const char *path, char *const argv[], char *const envp[])) { long ret = __llvm_libc::syscall_impl(SYS_execve, path, argv, envp); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } diff --git a/libc/src/unistd/linux/fchdir.cpp b/libc/src/unistd/linux/fchdir.cpp index 2d5aea3efa5d..fcdc0059d240 100644 --- a/libc/src/unistd/linux/fchdir.cpp +++ b/libc/src/unistd/linux/fchdir.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fchdir, (int fd)) { long ret = __llvm_libc::syscall_impl(SYS_fchdir, fd); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/unistd/linux/fork.cpp b/libc/src/unistd/linux/fork.cpp index 469c72e4ec3e..20fa0ee88418 100644 --- a/libc/src/unistd/linux/fork.cpp +++ b/libc/src/unistd/linux/fork.cpp @@ -13,7 +13,7 @@ #include "src/__support/threads/fork_callbacks.h" #include "src/__support/threads/thread.h" // For thread self object -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -42,7 +42,7 @@ LLVM_LIBC_FUNCTION(pid_t, fork, (void)) { if (ret < 0) { // Error case, a child process was not created. - errno = -ret; + libc_errno = -ret; return -1; } diff --git a/libc/src/unistd/linux/fsync.cpp b/libc/src/unistd/linux/fsync.cpp index 1665611321bb..3c581e90ae7f 100644 --- a/libc/src/unistd/linux/fsync.cpp +++ b/libc/src/unistd/linux/fsync.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fsync, (int fd)) { long ret = __llvm_libc::syscall_impl(SYS_fsync, fd); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/ftruncate.cpp b/libc/src/unistd/linux/ftruncate.cpp index f96d31e6c498..c400827ad11b 100644 --- a/libc/src/unistd/linux/ftruncate.cpp +++ b/libc/src/unistd/linux/ftruncate.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. #include @@ -20,7 +20,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, ftruncate, (int fd, off_t len)) { int ret = __llvm_libc::syscall_impl(SYS_ftruncate, fd, len); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/unistd/linux/getcwd.cpp b/libc/src/unistd/linux/getcwd.cpp index 67dea371ccb0..ea0cfd7aeba5 100644 --- a/libc/src/unistd/linux/getcwd.cpp +++ b/libc/src/unistd/linux/getcwd.cpp @@ -12,8 +12,8 @@ #include "src/__support/common.h" #include "src/string/allocating_string_utils.h" // For strdup. -#include #include // This is safe to include without any name pollution. +#include #include #include // For syscall numbers. @@ -24,10 +24,10 @@ namespace { bool getcwd_syscall(char *buf, size_t size) { int ret = __llvm_libc::syscall_impl(SYS_getcwd, buf, size); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return false; } else if (ret == 0 || buf[0] != '/') { - errno = ENOENT; + libc_errno = ENOENT; return false; } return true; @@ -46,12 +46,12 @@ LLVM_LIBC_FUNCTION(char *, getcwd, (char *buf, size_t size)) { return nullptr; auto cwd = internal::strdup(pathbuf); if (!cwd) { - errno = ENOMEM; + libc_errno = ENOMEM; return nullptr; } return *cwd; } else if (size == 0) { - errno = EINVAL; + libc_errno = EINVAL; return nullptr; } diff --git a/libc/src/unistd/linux/isatty.cpp b/libc/src/unistd/linux/isatty.cpp index 705d03cce113..1bdaedc6b71a 100644 --- a/libc/src/unistd/linux/isatty.cpp +++ b/libc/src/unistd/linux/isatty.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For ioctl numbers. #include // For syscall numbers. @@ -26,7 +26,7 @@ LLVM_LIBC_FUNCTION(int, isatty, (int fd)) { if (result == 0) return 1; - errno = -result; + libc_errno = -result; return 0; } diff --git a/libc/src/unistd/linux/link.cpp b/libc/src/unistd/linux/link.cpp index 2d77c37686ed..7a1ed8d07554 100644 --- a/libc/src/unistd/linux/link.cpp +++ b/libc/src/unistd/linux/link.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. @@ -27,7 +27,7 @@ LLVM_LIBC_FUNCTION(int, link, (const char *path1, const char *path2)) { #error "SYS_link or SYS_linkat not available." #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/linkat.cpp b/libc/src/unistd/linux/linkat.cpp index 170cd0abee34..d7271a178f93 100644 --- a/libc/src/unistd/linux/linkat.cpp +++ b/libc/src/unistd/linux/linkat.cpp @@ -11,8 +11,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include #include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -23,7 +23,7 @@ LLVM_LIBC_FUNCTION(int, linkat, long ret = __llvm_libc::syscall_impl(SYS_linkat, fd1, path1, fd2, path2, flags); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/lseek.cpp b/libc/src/unistd/linux/lseek.cpp index 07f93baa9469..aef3ffbcd488 100644 --- a/libc/src/unistd/linux/lseek.cpp +++ b/libc/src/unistd/linux/lseek.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "src/unistd/lseek.h" +#include "src/errno/libc_errno.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include #include // For syscall numbers. #include @@ -30,7 +30,7 @@ LLVM_LIBC_FUNCTION(off_t, lseek, (int fd, off_t offset, int whence)) { #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return result; diff --git a/libc/src/unistd/linux/pread.cpp b/libc/src/unistd/linux/pread.cpp index 1434f9781c2d..adf7303cfcff 100644 --- a/libc/src/unistd/linux/pread.cpp +++ b/libc/src/unistd/linux/pread.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -20,7 +20,7 @@ LLVM_LIBC_FUNCTION(ssize_t, pread, (int fd, void *buf, size_t count, off_t offset)) { long ret = __llvm_libc::syscall_impl(SYS_pread64, fd, buf, count, offset); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/pwrite.cpp b/libc/src/unistd/linux/pwrite.cpp index 597d266696b8..a18d7d565d2e 100644 --- a/libc/src/unistd/linux/pwrite.cpp +++ b/libc/src/unistd/linux/pwrite.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -20,7 +20,7 @@ LLVM_LIBC_FUNCTION(ssize_t, pwrite, (int fd, const void *buf, size_t count, off_t offset)) { long ret = __llvm_libc::syscall_impl(SYS_pwrite64, fd, buf, count, offset); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/read.cpp b/libc/src/unistd/linux/read.cpp index 468409d08e6f..fc9100bacc66 100644 --- a/libc/src/unistd/linux/read.cpp +++ b/libc/src/unistd/linux/read.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(ssize_t, read, (int fd, void *buf, size_t count)) { long ret = __llvm_libc::syscall_impl(SYS_read, fd, buf, count); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/readlink.cpp b/libc/src/unistd/linux/readlink.cpp index 713620e43c9a..ecd3feddbad9 100644 --- a/libc/src/unistd/linux/readlink.cpp +++ b/libc/src/unistd/linux/readlink.cpp @@ -11,8 +11,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include #include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -29,7 +29,7 @@ LLVM_LIBC_FUNCTION(ssize_t, readlink, #error "SYS_readlink or SYS_readlinkat not available." #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/readlinkat.cpp b/libc/src/unistd/linux/readlinkat.cpp index 8b0994a2622d..0cd84e3fe602 100644 --- a/libc/src/unistd/linux/readlinkat.cpp +++ b/libc/src/unistd/linux/readlinkat.cpp @@ -11,8 +11,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include #include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -23,7 +23,7 @@ LLVM_LIBC_FUNCTION(ssize_t, readlinkat, ssize_t ret = __llvm_libc::syscall_impl(SYS_readlinkat, fd, path, buf, bufsize); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/rmdir.cpp b/libc/src/unistd/linux/rmdir.cpp index 144a0902ffaf..08e72d0bb5af 100644 --- a/libc/src/unistd/linux/rmdir.cpp +++ b/libc/src/unistd/linux/rmdir.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. @@ -28,7 +28,7 @@ LLVM_LIBC_FUNCTION(int, rmdir, (const char *path)) { #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/unistd/linux/symlink.cpp b/libc/src/unistd/linux/symlink.cpp index caa07b0b4f9c..0c54510799ba 100644 --- a/libc/src/unistd/linux/symlink.cpp +++ b/libc/src/unistd/linux/symlink.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. @@ -26,7 +26,7 @@ LLVM_LIBC_FUNCTION(int, symlink, (const char *path1, const char *path2)) { #error "SYS_symlink or SYS_symlinkat not available." #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/symlinkat.cpp b/libc/src/unistd/linux/symlinkat.cpp index 25377b695934..c101a6a95fd6 100644 --- a/libc/src/unistd/linux/symlinkat.cpp +++ b/libc/src/unistd/linux/symlinkat.cpp @@ -11,8 +11,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include #include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -21,7 +21,7 @@ LLVM_LIBC_FUNCTION(int, symlinkat, (const char *path1, int fd, const char *path2)) { long ret = __llvm_libc::syscall_impl(SYS_symlinkat, path1, fd, path2); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/syscall.cpp b/libc/src/unistd/linux/syscall.cpp index 83884043484f..3af4c8aa8c35 100644 --- a/libc/src/unistd/linux/syscall.cpp +++ b/libc/src/unistd/linux/syscall.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include #include namespace __llvm_libc { @@ -24,7 +24,7 @@ LLVM_LIBC_FUNCTION(long, __llvm_libc_syscall, // Syscalls may return large positive values that overflow, but will never // return values between -4096 and -1 if (static_cast(ret) > -4096UL) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/libc/src/unistd/linux/sysconf.cpp b/libc/src/unistd/linux/sysconf.cpp index b4a9cd151e71..4066ded58799 100644 --- a/libc/src/unistd/linux/sysconf.cpp +++ b/libc/src/unistd/linux/sysconf.cpp @@ -10,8 +10,8 @@ #include "src/__support/common.h" -#include #include // For EXEC_PAGESIZE. +#include #include namespace __llvm_libc { @@ -24,7 +24,7 @@ LLVM_LIBC_FUNCTION(long, sysconf, (int name)) { } // TODO: Complete the rest of the sysconf options. if (ret < 0) { - errno = EINVAL; + libc_errno = EINVAL; return -1; } return ret; diff --git a/libc/src/unistd/linux/truncate.cpp b/libc/src/unistd/linux/truncate.cpp index 9ab05c15b81a..60b4c5395cbb 100644 --- a/libc/src/unistd/linux/truncate.cpp +++ b/libc/src/unistd/linux/truncate.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 // For syscall numbers. #include @@ -20,7 +20,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, truncate, (const char *path, off_t len)) { int ret = __llvm_libc::syscall_impl(SYS_truncate, path, len); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/unistd/linux/unlink.cpp b/libc/src/unistd/linux/unlink.cpp index 019b081e280c..62d16a417300 100644 --- a/libc/src/unistd/linux/unlink.cpp +++ b/libc/src/unistd/linux/unlink.cpp @@ -11,8 +11,8 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include #include +#include #include // For syscall numbers. namespace __llvm_libc { @@ -27,7 +27,7 @@ LLVM_LIBC_FUNCTION(int, unlink, (const char *path)) { #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/unistd/linux/unlinkat.cpp b/libc/src/unistd/linux/unlinkat.cpp index 9ca6108a6897..e39300ee13e2 100644 --- a/libc/src/unistd/linux/unlinkat.cpp +++ b/libc/src/unistd/linux/unlinkat.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. @@ -25,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, unlinkat, (int dfd, const char *path, int flags)) { #endif if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return 0; diff --git a/libc/src/unistd/linux/write.cpp b/libc/src/unistd/linux/write.cpp index 599ff4b23291..ba3bd0a82d06 100644 --- a/libc/src/unistd/linux/write.cpp +++ b/libc/src/unistd/linux/write.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 // For syscall numbers. namespace __llvm_libc { @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(ssize_t, write, (int fd, const void *buf, size_t count)) { long ret = __llvm_libc::syscall_impl(SYS_write, fd, buf, count); if (ret < 0) { - errno = -ret; + libc_errno = -ret; return -1; } return ret; diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index ef4b871c2e68..b89fe4c8e3f1 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -596,6 +596,16 @@ libc_support_library( ":libc_root", ], ) +############################### errno targets ################################ + +libc_function( + name = "errno", + srcs = ["src/errno/libc_errno.cpp"], + hdrs = ["src/errno/libc_errno.h"], + deps = [ + ":__support_common", + ], +) ################################ fenv targets ################################ @@ -1753,6 +1763,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1763,6 +1774,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1773,6 +1785,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1783,6 +1796,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1793,6 +1807,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1803,6 +1818,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1813,6 +1829,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1823,6 +1840,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1833,6 +1851,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1843,6 +1862,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1853,6 +1873,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1863,6 +1884,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1873,6 +1895,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1883,6 +1906,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1893,6 +1917,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1903,6 +1928,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1913,6 +1939,7 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1923,5 +1950,6 @@ libc_function( deps = [ ":__support_common", ":__support_osutil", + ":errno", ], )