Date: Wed, 24 Jan 2024 19:44:56 GMT From: Robert Clausecker <fuz@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: ddab9e646122 - stable/14 - lib/libc/amd64/string: implement strncat() by calling strlen(), memccpy() Message-ID: <202401241944.40OJiuUP005970@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=ddab9e646122df077570fc0dfb2af1516c098668 commit ddab9e646122df077570fc0dfb2af1516c098668 Author: Robert Clausecker <fuz@FreeBSD.org> AuthorDate: 2023-12-04 17:32:49 +0000 Commit: Robert Clausecker <fuz@FreeBSD.org> CommitDate: 2024-01-24 19:39:30 +0000 lib/libc/amd64/string: implement strncat() by calling strlen(), memccpy() This picks up the accelerated implementation of memccpy(). Tested by: developers@, exp-run Approved by: mjg MFC after: 1 month MFC to: stable/14 PR: 275785 Differential Revision: https://reviews.freebsd.org/D42902 (cherry picked from commit ea7b13771cc9d45bf1bc6c6edad8d1b7bce12990) --- lib/libc/amd64/string/Makefile.inc | 1 + lib/libc/amd64/string/strncat.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/libc/amd64/string/Makefile.inc b/lib/libc/amd64/string/Makefile.inc index b569d2cb8be8..a14e8a768f01 100644 --- a/lib/libc/amd64/string/Makefile.inc +++ b/lib/libc/amd64/string/Makefile.inc @@ -17,6 +17,7 @@ MDSRCS+= \ strlcat.c \ strlcpy.S \ strlen.S \ + strncat.c \ strncmp.S \ strncpy.c \ strnlen.c \ diff --git a/lib/libc/amd64/string/strncat.c b/lib/libc/amd64/string/strncat.c new file mode 100644 index 000000000000..33b278ac5e04 --- /dev/null +++ b/lib/libc/amd64/string/strncat.c @@ -0,0 +1,29 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Robert Clausecker + */ + +#include <sys/cdefs.h> + +#include <string.h> + +void *__memccpy(void *restrict, const void *restrict, int, size_t); + +char * +strncat(char *dest, const char *src, size_t n) +{ + size_t len; + char *endptr; + + len = strlen(dest); + endptr = __memccpy(dest + len, src, '\0', n); + + /* avoid an extra branch */ + if (endptr == NULL) + endptr = dest + len + n + 1; + + endptr[-1] = '\0'; + + return (dest); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401241944.40OJiuUP005970>