1 //===-- Implementation of strlcpy -----------------------------------------===// 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/strlcpy.h" 10 #include "src/string/bzero.h" 11 #include "src/string/memory_utils/memcpy_implementations.h" 12 #include "src/string/memory_utils/memset_implementations.h" 13 #include "src/string/string_utils.h" 14 15 #include "src/__support/common.h" 16 17 namespace __llvm_libc { 18 19 LLVM_LIBC_FUNCTION(size_t, strlcpy, 20 (char *__restrict dst, const char *__restrict src, 21 size_t size)) { 22 size_t len = internal::string_length(src); 23 if (!size) 24 return len; 25 size_t n = len < size - 1 ? len : size - 1; 26 inline_memcpy(dst, src, n); 27 inline_memset(dst + n, 0, size - n); 28 return len; 29 } 30 31 } // namespace __llvm_libc 32