diff options
Diffstat (limited to 'libc/src')
-rw-r--r-- | libc/src/unistd/CMakeLists.txt | 7 | ||||
-rw-r--r-- | libc/src/unistd/faccessat.h | 20 | ||||
-rw-r--r-- | libc/src/unistd/linux/CMakeLists.txt | 13 | ||||
-rw-r--r-- | libc/src/unistd/linux/access.cpp | 2 | ||||
-rw-r--r-- | libc/src/unistd/linux/faccessat.cpp | 37 |
5 files changed, 78 insertions, 1 deletions
diff --git a/libc/src/unistd/CMakeLists.txt b/libc/src/unistd/CMakeLists.txt index c66a3a4..78c3bf8 100644 --- a/libc/src/unistd/CMakeLists.txt +++ b/libc/src/unistd/CMakeLists.txt @@ -56,6 +56,13 @@ add_entrypoint_object( ) add_entrypoint_object( + faccessat + ALIAS + DEPENDS + .${LIBC_TARGET_OS}.faccessat +) + +add_entrypoint_object( fchdir ALIAS DEPENDS diff --git a/libc/src/unistd/faccessat.h b/libc/src/unistd/faccessat.h new file mode 100644 index 0000000..0dc834d --- /dev/null +++ b/libc/src/unistd/faccessat.h @@ -0,0 +1,20 @@ +//===-- Implementation header for faccessat ---------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_UNISTD_FACCESSAT_H +#define LLVM_LIBC_SRC_UNISTD_FACCESSAT_H + +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +int faccessat(int fd, const char *path, int amode, int flag); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_UNISTD_FACCESSAT_H diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt index 2d510f3..dff6ba2 100644 --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -81,6 +81,19 @@ add_entrypoint_object( ) add_entrypoint_object( + faccessat + SRCS + faccessat.cpp + HDRS + ../faccessat.h + DEPENDS + libc.hdr.fcntl_macros + libc.include.sys_syscall + libc.src.__support.OSUtil.osutil + libc.src.errno.errno +) + +add_entrypoint_object( fchdir SRCS fchdir.cpp diff --git a/libc/src/unistd/linux/access.cpp b/libc/src/unistd/linux/access.cpp index 55cd6ad..f06eec5 100644 --- a/libc/src/unistd/linux/access.cpp +++ b/libc/src/unistd/linux/access.cpp @@ -23,7 +23,7 @@ LLVM_LIBC_FUNCTION(int, access, (const char *path, int mode)) { int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_access, path, mode); #elif defined(SYS_faccessat) int ret = - LIBC_NAMESPACE::syscall_impl<int>(SYS_faccessat, AT_FDCWD, path, mode, 0); + LIBC_NAMESPACE::syscall_impl<int>(SYS_faccessat, AT_FDCWD, path, mode); #else #error "access and faccessat syscalls not available." #endif diff --git a/libc/src/unistd/linux/faccessat.cpp b/libc/src/unistd/linux/faccessat.cpp new file mode 100644 index 0000000..7a2a29c --- /dev/null +++ b/libc/src/unistd/linux/faccessat.cpp @@ -0,0 +1,37 @@ +//===-- Linux implementation of faccessat ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/unistd/faccessat.h" + +#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/common.h" + +#include "hdr/fcntl_macros.h" +#include "src/__support/libc_errno.h" +#include "src/__support/macros/config.h" +#include <sys/syscall.h> // For syscall numbers. + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(int, faccessat, + (int fd, const char *path, int amode, int flag)) { +#ifdef SYS_faccessat2 + int ret = + LIBC_NAMESPACE::syscall_impl<int>(SYS_faccessat2, fd, path, amode, flag); +#else +#error "faccessat2 syscall is not available." +#endif + + if (ret < 0) { + libc_errno = -ret; + return -1; + } + return 0; +} + +} // namespace LIBC_NAMESPACE_DECL |