libc.src.unistd.rmdir
libc.src.unistd.symlink
libc.src.unistd.symlinkat
+ libc.src.unistd.sysconf
libc.src.unistd.truncate
libc.src.unistd.unlink
libc.src.unistd.unlinkat
#define W_OK 2
#define R_OK 4
+#define _SC_PAGESIZE 1
+#define _SC_PAGE_SIZE _SC_PAGESIZE
+
// Macro to set up the call to the __llvm_libc_syscall function
// This is to prevent the call from having fewer than 6 arguments, since six
// arguments are always passed to the syscall. Unnecessary arguments are
[ArgSpec<IntType>, ArgSpec<ConstCharPtr>, ArgSpec<IntType>, ArgSpec<ConstCharPtr>]
>,
FunctionSpec<
+ "sysconf",
+ RetValSpec<IntType>,
+ [ArgSpec<IntType>]
+ >,
+ FunctionSpec<
"__llvm_libc_syscall",
RetValSpec<LongType>,
[ArgSpec<LongType>,ArgSpec<LongType>,ArgSpec<LongType>,ArgSpec<LongType>,ArgSpec<LongType>,ArgSpec<LongType>,ArgSpec<LongType>]
)
add_entrypoint_object(
+ sysconf
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.sysconf
+)
+
+add_entrypoint_object(
truncate
ALIAS
DEPENDS
)
add_entrypoint_object(
+ sysconf
+ SRCS
+ sysconf.cpp
+ HDRS
+ ../sysconf.h
+ DEPENDS
+ libc.include.unistd
+ libc.src.errno.errno
+)
+
+add_entrypoint_object(
truncate
SRCS
truncate.cpp
--- /dev/null
+//===-- Linux implementation of sysconf -----------------------------------===//
+//
+// 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/sysconf.h"
+
+#include "src/__support/common.h"
+
+#include <errno.h>
+#include <linux/param.h> // For EXEC_PAGESIZE.
+#include <unistd.h>
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(long, sysconf, (int name)) {
+ long ret = 0;
+ if (name == _SC_PAGESIZE) {
+ // TODO: get this information from the auxvector.
+ return EXEC_PAGESIZE;
+ }
+ // TODO: Complete the rest of the sysconf options.
+ if (ret < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ return ret;
+}
+
+} // namespace __llvm_libc
--- /dev/null
+//===-- Implementation header for sysconf -----------------------*- 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_SYSCONF_H
+#define LLVM_LIBC_SRC_UNISTD_SYSCONF_H
+
+#include <unistd.h>
+
+namespace __llvm_libc {
+
+long sysconf(int name);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_UNISTD_SYSCONF_H
libc.include.sys_syscall
libc.test.errno_setter_matcher
)
+
+
+add_libc_unittest(
+ sysconf_test
+ SUITE
+ libc_unistd_unittests
+ SRCS
+ sysconf_test.cpp
+ DEPENDS
+ libc.include.unistd
+ libc.src.unistd.sysconf
+)
--- /dev/null
+//===-- Unittests for sysconf ---------------------------------------------===//
+//
+// 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/sysconf.h"
+#include "utils/UnitTest/Test.h"
+
+#include <unistd.h>
+
+TEST(LlvmLibcSysconfTest, PagesizeTest) {
+ long pagesize = __llvm_libc::sysconf(_SC_PAGESIZE);
+ ASSERT_GT(pagesize, 0l);
+}