xref: /freebsd/lib/libc/amd64/string/strncat.c (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
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 *__memccpy(void *restrict, const void *restrict, int, size_t);
12 
13 char *
14 strncat(char *dest, const char *src, size_t n)
15 {
16 	size_t len;
17 	char *endptr;
18 
19 	len = strlen(dest);
20 	endptr = __memccpy(dest + len, src, '\0', n);
21 
22 	/* avoid an extra branch */
23 	if (endptr == NULL)
24 		endptr = dest + len + n + 1;
25 
26 	endptr[-1] = '\0';
27 
28 	return (dest);
29 }
30