summaryrefslogtreecommitdiff
path: root/lib/libc/string/strlcpy.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/string/strlcpy.c')
-rw-r--r--lib/libc/string/strlcpy.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/libc/string/strlcpy.c b/lib/libc/string/strlcpy.c
new file mode 100644
index 00000000..2f2f6a3b
--- /dev/null
+++ b/lib/libc/string/strlcpy.c
@@ -0,0 +1,16 @@
+#include <string.h>
+
+size_t strlcpy(char *restrict dst, const char *restrict src, size_t dstsize)
+{
+ size_t srclen = strlen(src);
+
+ if (dstsize == 0) {
+ return srclen;
+ }
+
+ size_t copylen = srclen < dstsize - 1 ? srclen : dstsize - 1;
+ memcpy(dst, src, copylen);
+ dst[copylen] = '\0';
+
+ return srclen;
+}