Path: blob/main/system/lib/llvm-libc/src/string/stpncpy.cpp
6175 views
//===-- Implementation of stpncpy -----------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "src/string/stpncpy.h"9#include "src/__support/macros/config.h"10#include "src/__support/macros/null_check.h"11#include "src/string/memory_utils/inline_bzero.h"1213#include "src/__support/common.h"1415namespace LIBC_NAMESPACE_DECL {1617LLVM_LIBC_FUNCTION(char *, stpncpy,18(char *__restrict dest, const char *__restrict src,19size_t n)) {20if (n) {21LIBC_CRASH_ON_NULLPTR(dest);22LIBC_CRASH_ON_NULLPTR(src);23}24size_t i;25// Copy up until \0 is found.26for (i = 0; i < n && src[i] != '\0'; ++i)27dest[i] = src[i];28// When n>strlen(src), n-strlen(src) \0 are appended.29if (n > i)30inline_bzero(dest + i, n - i);31return dest + i;32}3334} // namespace LIBC_NAMESPACE_DECL353637