summaryrefslogtreecommitdiff
path: root/lib/string/strlcat.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/string/strlcat.c')
-rw-r--r--lib/string/strlcat.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/string/strlcat.c b/lib/string/strlcat.c
new file mode 100644
index 0000000..a61821d
--- /dev/null
+++ b/lib/string/strlcat.c
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: MIT */
+/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */
+
+#define _BSD_SOURCE
+#include <string.h>
+
+size_t strlcat(char *d, const char *s, size_t n)
+{
+ size_t l = strnlen(d, n);
+ if (l == n) return l + strlen(s);
+ return l + strlcpy(d+l, s, n-l);
+}