[libc][NFC] Switch use of errno in src/unistd and src/sys to libc_errno.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145096
This commit is contained in:
Siva Chandra Reddy 2023-03-01 17:41:02 +00:00
parent ae9e1d1df4
commit 204587a3cb
52 changed files with 130 additions and 110 deletions

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/syscall.h> // 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;
}

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <linux/param.h> // For EXEC_PAGESIZE.
#include <sys/syscall.h> // 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;
}

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/syscall.h> // 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;
}

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/syscall.h> // 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;
}

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/resource.h> // For struct rlimit
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/resource.h> // For struct rlimit
#include <sys/syscall.h> // 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;

View File

@ -12,7 +12,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <signal.h>
#include <stddef.h> // For size_t
#include <sys/select.h>
@ -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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/sendfile.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/stat.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/stat.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/syscall.h> // For syscall numbers.
#include <sys/utsname.h>
@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(int, uname, (struct utsname * name)) {
if (ret >= 0)
return 1;
errno = -ret;
libc_errno = -ret;
return -1;
}

View File

@ -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

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/syscall.h> // For syscall numbers.
#include <sys/wait.h>
@ -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;
}

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/syscall.h> // For syscall numbers.
#include <sys/wait.h>
@ -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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"
#include <sys/syscall.h> // For syscall numbers.
#include <sys/wait.h>
@ -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;

View File

@ -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

View File

@ -11,8 +11,8 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <fcntl.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,8 +11,8 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <fcntl.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;
}

View File

@ -12,7 +12,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;
}

View File

@ -12,7 +12,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;
}

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -13,7 +13,7 @@
#include "src/__support/threads/fork_callbacks.h"
#include "src/__support/threads/thread.h" // For thread self object
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;
}

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // For syscall numbers.
#include <unistd.h>
@ -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;

View File

@ -12,8 +12,8 @@
#include "src/__support/common.h"
#include "src/string/allocating_string_utils.h" // For strdup.
#include <errno.h>
#include <linux/limits.h> // This is safe to include without any name pollution.
#include <src/errno/libc_errno.h>
#include <stdlib.h>
#include <sys/syscall.h> // 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;
}

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/ioctl.h> // For ioctl numbers.
#include <sys/syscall.h> // 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;
}

View File

@ -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 <errno.h>
#include <fcntl.h>
#include <sys/syscall.h> // 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;

View File

@ -11,8 +11,8 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <fcntl.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -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 <errno.h>
#include <sys/syscall.h> // For syscall numbers.
#include <unistd.h>
@ -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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,8 +11,8 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <fcntl.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,8 +11,8 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <fcntl.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -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 <errno.h>
#include <fcntl.h>
#include <sys/syscall.h> // 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;

View File

@ -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 <errno.h>
#include <fcntl.h>
#include <sys/syscall.h> // 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;

View File

@ -11,8 +11,8 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <fcntl.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -11,7 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <src/errno/libc_errno.h>
#include <stdarg.h>
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<unsigned long>(ret) > -4096UL) {
errno = -ret;
libc_errno = -ret;
return -1;
}
return ret;

View File

@ -10,8 +10,8 @@
#include "src/__support/common.h"
#include <errno.h>
#include <linux/param.h> // For EXEC_PAGESIZE.
#include <src/errno/libc_errno.h>
#include <unistd.h>
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;

View File

@ -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 <errno.h>
#include <sys/syscall.h> // For syscall numbers.
#include <unistd.h>
@ -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;

View File

@ -11,8 +11,8 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include <errno.h>
#include <fcntl.h>
#include <src/errno/libc_errno.h>
#include <sys/syscall.h> // 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;

View File

@ -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 <errno.h>
#include <fcntl.h>
#include <sys/syscall.h> // 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;

View File

@ -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 <errno.h>
#include <sys/syscall.h> // 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;

View File

@ -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",
],
)