brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 6d8bb69 Raw
35 lines · cpp
1//===-- Implementation of strncat -----------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/string/strncat.h"10#include "src/__support/macros/config.h"11#include "src/__support/macros/null_check.h"12#include "src/string/string_utils.h"13 14#include "src/__support/common.h"15 16namespace LIBC_NAMESPACE_DECL {17 18LLVM_LIBC_FUNCTION(char *, strncat,19                   (char *__restrict dest, const char *__restrict src,20                    size_t count)) {21  if (count) {22    LIBC_CRASH_ON_NULLPTR(dest);23    LIBC_CRASH_ON_NULLPTR(src);24  }25  size_t dest_length = internal::string_length(dest);26  size_t i;27  for (i = 0; i < count && src[i] != '\0'; ++i)28    dest[dest_length + i] = src[i];29 30  dest[dest_length + i] = '\0';31  return dest;32}33 34} // namespace LIBC_NAMESPACE_DECL35