git: 3045c0f198a1 - stable/14 - lib/libc/amd64/string: implement strlcat() through strlcpy()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 24 Jan 2024 19:44:49 UTC
The branch stable/14 has been updated by fuz:
URL: https://cgit.FreeBSD.org/src/commit/?id=3045c0f198a1113a02f44f77b161fcf79380ae63
commit 3045c0f198a1113a02f44f77b161fcf79380ae63
Author: Robert Clausecker <fuz@FreeBSD.org>
AuthorDate: 2023-11-29 02:32:28 +0000
Commit: Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2024-01-24 19:39:29 +0000
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)
---
lib/libc/amd64/string/Makefile.inc | 1 +
lib/libc/amd64/string/strlcat.c | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/lib/libc/amd64/string/Makefile.inc b/lib/libc/amd64/string/Makefile.inc
index 03bca498e116..2b1e276cb3da 100644
--- a/lib/libc/amd64/string/Makefile.inc
+++ b/lib/libc/amd64/string/Makefile.inc
@@ -13,6 +13,7 @@ MDSRCS+= \
strcmp.S \
strcpy.c \
strcspn.S \
+ strlcat.c \
strlcpy.S \
strlen.S \
strncmp.S \
diff --git a/lib/libc/amd64/string/strlcat.c b/lib/libc/amd64/string/strlcat.c
new file mode 100644
index 000000000000..0c1e1c5d05f7
--- /dev/null
+++ b/lib/libc/amd64/string/strlcat.c
@@ -0,0 +1,25 @@
+/*-
+ * 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));
+}