19e9803bfSMichael Jones //===-- Implementation of strncat -----------------------------------------===// 29e9803bfSMichael Jones // 39e9803bfSMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 49e9803bfSMichael Jones // See https://llvm.org/LICENSE.txt for license information. 59e9803bfSMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 69e9803bfSMichael Jones // 79e9803bfSMichael Jones //===----------------------------------------------------------------------===// 89e9803bfSMichael Jones 99e9803bfSMichael Jones #include "src/string/strncat.h" 10*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 119e9803bfSMichael Jones #include "src/string/string_utils.h" 129e9803bfSMichael Jones #include "src/string/strncpy.h" 139e9803bfSMichael Jones 149e9803bfSMichael Jones #include "src/__support/common.h" 159e9803bfSMichael Jones 16*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 179e9803bfSMichael Jones 189e9803bfSMichael Jones LLVM_LIBC_FUNCTION(char *, strncat, 199e9803bfSMichael Jones (char *__restrict dest, const char *__restrict src, 209e9803bfSMichael Jones size_t count)) { 211c92911eSMichael Jones size_t src_length = internal::string_length(src); 221c92911eSMichael Jones size_t copy_amount = src_length > count ? count : src_length; 231c92911eSMichael Jones size_t dest_length = internal::string_length(dest); 24b6bc9d72SGuillaume Chatelet LIBC_NAMESPACE::strncpy(dest + dest_length, src, copy_amount); 251c92911eSMichael Jones dest[dest_length + copy_amount] = '\0'; 269e9803bfSMichael Jones return dest; 279e9803bfSMichael Jones } 289e9803bfSMichael Jones 29*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 30