diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -29,6 +29,7 @@ libc.src.string.strcpy libc.src.string.strcspn libc.src.string.strlen + libc.src.string.strncpy libc.src.string.strnlen libc.src.string.strpbrk libc.src.string.strrchr diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -47,6 +47,7 @@ libc.src.string.strcpy libc.src.string.strcspn libc.src.string.strlen + libc.src.string.strncpy libc.src.string.strnlen libc.src.string.strpbrk libc.src.string.strrchr diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -74,6 +74,14 @@ strstr.h ) +add_entrypoint_object( + strncpy + SRCS + strncpy.cpp + HDRS + strncpy.h +) + add_entrypoint_object( strnlen SRCS diff --git a/libc/src/string/strncpy.h b/libc/src/string/strncpy.h new file mode 100644 --- /dev/null +++ b/libc/src/string/strncpy.h @@ -0,0 +1,20 @@ +//===-- Implementation header for strncpy -----------------------*- 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_STRING_STRNCPY_H +#define LLVM_LIBC_SRC_STRING_STRNCPY_H + +#include + +namespace __llvm_libc { + +char *strncpy(char *__restrict dest, const char *__restrict src, size_t n); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_STRING_STRNCPY_H diff --git a/libc/src/string/strncpy.cpp b/libc/src/string/strncpy.cpp new file mode 100644 --- /dev/null +++ b/libc/src/string/strncpy.cpp @@ -0,0 +1,29 @@ +//===-- Implementation of strncpy -----------------------------------------===// +// +// 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/string/strncpy.h" + +#include "src/__support/common.h" +#include + +namespace __llvm_libc { + +// If strlen(src)