xref: /freebsd/lib/libc/amd64/string/strlcat.c (revision 87bf66d4a7488c496af110d4d05cc0273d49f82e)
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 #undef strlcat	/* FORTIFY_SOURCE */
12 
13 void *__memchr(const void *, int, size_t);
14 size_t __strlcpy(char *restrict, const char *restrict, size_t);
15 
16 size_t
17 strlcat(char *restrict dst, const char *restrict src, size_t dstsize)
18 {
19 	char *loc = __memchr(dst, '\0', dstsize);
20 
21 	if (loc != NULL) {
22 		size_t dstlen = (size_t)(loc - dst);
23 
24 		return (dstlen + __strlcpy(loc, src, dstsize - dstlen));
25 	} else
26 		return (dstsize + strlen(src));
27 }
28