libc.src.sys.stat.mkdir
libc.src.sys.stat.mkdirat
+ # sys/utsname.h entrypoints
+ libc.src.sys.utsname.uname
+
# unistd.h entrypoints
libc.src.unistd.access
libc.src.unistd.chdir
def SysSendfileAPI : PublicAPI<"sys/sendfile.h"> {
let Types = ["off_t", "size_t", "ssize_t"];
}
+
+def SysUtsNameAPI : PublicAPI<"sys/utsname.h"> {
+ let Types = ["struct utsname"];
+}
libc.src.sys.stat.mkdir
libc.src.sys.stat.mkdirat
+ # sys/utsname.h entrypoints
+ libc.src.sys.utsname.uname
+
# unistd.h entrypoints
libc.src.unistd.access
libc.src.unistd.chdir
../config/${LIBC_TARGET_OS}/syscall_numbers.h.inc
)
+add_gen_header(
+ sys_utsname
+ DEF_FILE sys/utsname.h.def
+ GEN_HDR sys/utsname.h
+ DEPENDS
+ .llvm_libc_common_h
+ .llvm-libc-types.struct_utsname
+)
+
if(NOT LLVM_LIBC_FULL_BUILD)
# We don't install headers in non-fullbuild mode.
return()
add_header(struct_dirent HDR struct_dirent.h DEPENDS .ino_t .off_t)
add_header(struct_sigaction HDR struct_sigaction.h)
add_header(struct_tm HDR struct_tm.h)
+add_header(struct_utsname HDR struct_utsname.h)
add_header(thrd_start_t HDR thrd_start_t.h)
add_header(thrd_t HDR thrd_t.h DEPENDS .__thread_type)
add_header(time_t HDR time_t.h)
--- /dev/null
+//===-- Definition of struct utsname --------------------------------------===//
+//
+// 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_TYPES_STRUCT_UTSNAME_H__
+#define __LLVM_LIBC_TYPES_STRUCT_UTSNAME_H__
+
+#ifdef __unix__
+#define __UTS_NAME_LENGTH 65
+#else
+// Arbitray default. Should be specialized for each platform.
+#define __UTS_NAME_LENGTH 1024
+#endif
+
+struct utsname {
+ char sysname[__UTS_NAME_LENGTH];
+ char nodename[__UTS_NAME_LENGTH];
+ char release[__UTS_NAME_LENGTH];
+ char version[__UTS_NAME_LENGTH];
+ char machine[__UTS_NAME_LENGTH];
+#ifdef __unix__
+ char domainname[__UTS_NAME_LENGTH];
+#endif
+};
+
+#undef __UTS_NAME_LENGTH
+
+#endif // __LLVM_LIBC_TYPES_STRUCT_UTSNAME_H__
--- /dev/null
+//===-- Linux sys/utsname.h -----------------------------------------------===//
+//
+// 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_SYS_UTSNAME_H
+#define LLVM_LIBC_SYS_UTSNAME_H
+
+#include <__llvm-libc-common.h>
+
+%%public_api()
+
+#endif // LLVM_LIBC_SYS_UTSNAME_H
]
>;
+ NamedType StructUtsName = NamedType<"struct utsname">;
+ PtrType StructUtsNamePtr = PtrType<StructUtsName>;
+ HeaderSpec SysUtsName = HeaderSpec<
+ "sys/utsname.h",
+ [], // Macros
+ [StructUtsName], // Types
+ [], // Enumerations
+ [
+ FunctionSpec<
+ "uname",
+ RetValSpec<IntType>,
+ [ArgSpec<StructUtsNamePtr>]
+ >,
+ ]
+ >;
+
HeaderSpec PThread = HeaderSpec<
"pthread.h",
[], // Macros
SysMMan,
SysResource,
SysStat,
+ SysUtsName,
UniStd,
String
];
add_subdirectory(resource)
add_subdirectory(sendfile)
add_subdirectory(stat)
+add_subdirectory(utsname)
--- /dev/null
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+endif()
+
+add_entrypoint_object(
+ uname
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.uname
+)
--- /dev/null
+add_entrypoint_object(
+ uname
+ SRCS
+ uname.cpp
+ HDRS
+ ../uname.h
+ DEPENDS
+ libc.include.sys_utsname
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
+
--- /dev/null
+//===-- Linux implementation of uname -------------------------------------===//
+//
+// 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/sys/utsname/uname.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 <sys/utsname.h>
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(int, uname, (struct utsname * name)) {
+ long ret = __llvm_libc::syscall(SYS_uname, name);
+
+ if (ret >= 0)
+ return 1;
+ errno = -ret;
+ return -1;
+}
+
+} // namespace __llvm_libc
--- /dev/null
+//===-- Implementation header for uname -------------------------*- 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_SYS_UTSNAME_UNAME_H
+#define LLVM_LIBC_SRC_SYS_UTSNAME_UNAME_H
+
+#include <sys/utsname.h>
+
+namespace __llvm_libc {
+
+int uname(struct utsname *name);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SYS_UTSNAME_UNAME_H
add_subdirectory(resource)
add_subdirectory(sendfile)
add_subdirectory(stat)
+add_subdirectory(utsname)
--- /dev/null
+add_libc_testsuite(libc_sys_utsname_unittests)
+
+add_libc_unittest(
+ uname_test
+ SUITE
+ libc_sys_utsname_unittests
+ SRCS
+ uname_test.cpp
+ DEPENDS
+ libc.include.errno
+ libc.include.sys_utsname
+ libc.src.__support.common
+ libc.src.sys.utsname.uname
+ libc.test.errno_setter_matcher
+)
--- /dev/null
+//===-- Unittests for uname -----------------------------------------------===//
+//
+// 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/__support/CPP/string_view.h"
+#include "src/__support/architectures.h"
+#include "src/sys/utsname/uname.h"
+#include "test/ErrnoSetterMatcher.h"
+#include "utils/UnitTest/Test.h"
+
+#include <errno.h>
+#include <sys/utsname.h>
+
+TEST(LlvmLibcUnameTest, GetMachineName) {
+ struct utsname names;
+ ASSERT_GE(__llvm_libc::uname(&names), 0);
+#ifdef LLVM_LIBC_ARCH_X86_64
+ ASSERT_STREQ(names.machine, "x86_64");
+#elif defined(LLVM_LIBC_ARCH_AARCH64)
+ ASSERT_STREQ(names.machine, "aarch64");
+#endif
+}