diff --git a/libc/src/sys/mman/linux/madvise.cpp b/libc/src/sys/mman/linux/madvise.cpp --- 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 @@ // 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 --- 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 @@ // 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 --- 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 @@ // 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 --- 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 @@ // 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 --- 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 @@ (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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ #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 --- 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 @@ 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 --- 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 @@ (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 --- 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 @@ #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 --- 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 @@ #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 --- 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 @@ 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 --- a/libc/src/sys/wait/linux/CMakeLists.txt +++ b/libc/src/sys/wait/linux/CMakeLists.txt @@ -5,7 +5,6 @@ HDRS ../wait.h DEPENDS - libc.include.errno libc.include.sys_wait libc.include.sys_syscall libc.src.__support.OSUtil.osutil @@ -19,7 +18,6 @@ HDRS ../wait4.h DEPENDS - libc.include.errno libc.include.sys_wait libc.include.sys_syscall libc.src.__support.OSUtil.osutil @@ -33,7 +31,6 @@ 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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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 --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -97,7 +97,6 @@ HDRS ../fork.h DEPENDS - libc.include.errno libc.include.unistd libc.include.sys_syscall libc.src.__support.threads.fork_callbacks @@ -113,7 +112,6 @@ HDRS ../execv.h DEPENDS - libc.include.errno libc.include.sys_syscall libc.src.__support.OSUtil.osutil libc.src.errno.errno @@ -127,7 +125,6 @@ HDRS ../execve.h DEPENDS - libc.include.errno libc.include.sys_syscall libc.src.__support.OSUtil.osutil libc.src.errno.errno @@ -166,7 +163,6 @@ HDRS ../getcwd.h DEPENDS - libc.include.errno libc.include.stdlib libc.include.unistd libc.include.sys_syscall @@ -230,7 +226,6 @@ ../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 --- 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 @@ #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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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 @@ #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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ (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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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 @@ 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 --- 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 @@ 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 --- 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 @@ #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 --- 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 @@ 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 --- 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 @@ #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 --- 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 @@ (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 --- 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 @@ (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 --- 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 @@ 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 --- 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 @@ #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 --- 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 @@ 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 --- 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 @@ #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 --- 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 @@ #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 --- 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 @@ (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 --- 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 @@ // 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 --- 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 @@ } // 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 --- 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 @@ 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 --- 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 @@ #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 --- 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 @@ #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 --- 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 @@ 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 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -596,6 +596,16 @@ ":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 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1763,6 +1774,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1773,6 +1785,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1783,6 +1796,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1793,6 +1807,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1803,6 +1818,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1813,6 +1829,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1823,6 +1840,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1833,6 +1851,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1843,6 +1862,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1853,6 +1873,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1863,6 +1884,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1873,6 +1895,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1883,6 +1906,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1893,6 +1917,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1903,6 +1928,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1913,6 +1939,7 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], ) @@ -1923,5 +1950,6 @@ deps = [ ":__support_common", ":__support_osutil", + ":errno", ], )