xref: /freebsd/lib/libc/amd64/string/strlcat.c (revision f5463265955b829775bbb32e1fd0bc11dafc36ce)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2023 Robert Clausecker
5  */
6 
7 #include <sys/cdefs.h>
8 
9 #include <string.h>
10 
11 void *__memchr(const void *, int, size_t);
12 size_t __strlcpy(char *restrict, const char *restrict, size_t);
13 
14 size_t
15 strlcat(char *restrict dst, const char *restrict src, size_t dstsize)
16 {
17 	char *loc = __memchr(dst, '\0', dstsize);
18 
19 	if (loc != NULL) {
20 		size_t dstlen = (size_t)(loc - dst);
21 
22 		return (dstlen + __strlcpy(loc, src, dstsize - dstlen));
23 	} else
24 		return (dstsize + strlen(src));
25 }
26