opnsense-src/lib/libc/amd64/string/strlcat.c
Robert Clausecker 3045c0f198 lib/libc/amd64/string: implement strlcat() through strlcpy()
This should pick up our optimised memchr(), strlen(), and strlcpy()
when strlcat() is called.

Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42863

(cherry picked from commit 2b7b03b7ae179db465c1ef19a5007f729874916a)
2024-01-24 20:39:29 +01:00

25 lines
532 B
C

/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2023 Robert Clausecker
*/
#include <sys/cdefs.h>
#include <string.h>
void *__memchr(const void *, int, size_t);
size_t __strlcpy(char *restrict, const char *restrict, size_t);
size_t
strlcat(char *restrict dst, const char *restrict src, size_t dstsize)
{
char *loc = __memchr(dst, '\0', dstsize);
if (loc != NULL) {
size_t dstlen = (size_t)(loc - dst);
return (dstlen + __strlcpy(loc, src, dstsize - dstlen));
} else
return (dstsize + strlen(src));
}