summaryrefslogtreecommitdiff
path: root/lib/libc/string/strlcpy.c
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
commitfc00c656c96528112d05cf0edf8631bd5eaea446 (patch)
treea6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/string/strlcpy.c
Add build system scaffolding and libc headers
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;
+}