1 //===-- Implementation of strlcat -----------------------------------------===// 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/string/strlcat.h" 10 #include "src/string/string_utils.h" 11 12 #include "src/__support/common.h" 13 14 namespace __llvm_libc { 15 16 LLVM_LIBC_FUNCTION(size_t, strlcat, 17 (char *__restrict dst, const char *__restrict src, 18 size_t size)) { 19 char *new_dst = reinterpret_cast<char *>(internal::find_first_character( 20 reinterpret_cast<unsigned char *>(dst), 0, size)); 21 if (!new_dst) 22 return size + internal::string_length(src); 23 size_t first_len = new_dst - dst; 24 return first_len + internal::strlcpy(new_dst, src, size - first_len); 25 } 26 27 } // namespace __llvm_libc 28