1*b1183305SAlex Brachet //===-- Implementation of strlcat -----------------------------------------===//
2*b1183305SAlex Brachet //
3*b1183305SAlex Brachet // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*b1183305SAlex Brachet // See https://llvm.org/LICENSE.txt for license information.
5*b1183305SAlex Brachet // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*b1183305SAlex Brachet //
7*b1183305SAlex Brachet //===----------------------------------------------------------------------===//
8*b1183305SAlex Brachet 
9*b1183305SAlex Brachet #include "src/string/strlcat.h"
10*b1183305SAlex Brachet #include "src/string/string_utils.h"
11*b1183305SAlex Brachet 
12*b1183305SAlex Brachet #include "src/__support/common.h"
13*b1183305SAlex Brachet 
14*b1183305SAlex Brachet namespace __llvm_libc {
15*b1183305SAlex Brachet 
16*b1183305SAlex Brachet LLVM_LIBC_FUNCTION(size_t, strlcat,
17*b1183305SAlex Brachet                    (char *__restrict dst, const char *__restrict src,
18*b1183305SAlex Brachet                     size_t size)) {
19*b1183305SAlex Brachet   char *new_dst = reinterpret_cast<char *>(internal::find_first_character(
20*b1183305SAlex Brachet       reinterpret_cast<unsigned char *>(dst), 0, size));
21*b1183305SAlex Brachet   if (!new_dst)
22*b1183305SAlex Brachet     return size + internal::string_length(src);
23*b1183305SAlex Brachet   size_t first_len = new_dst - dst;
24*b1183305SAlex Brachet   return first_len + internal::strlcpy(new_dst, src, size - first_len);
25*b1183305SAlex Brachet }
26*b1183305SAlex Brachet 
27*b1183305SAlex Brachet } // namespace __llvm_libc
28