From fc00c656c96528112d05cf0edf8631bd5eaea446 Mon Sep 17 00:00:00 2001 From: Kacper Date: Sun, 7 Dec 2025 20:10:31 +0100 Subject: Add build system scaffolding and libc headers --- lib/libc/string/strlcpy.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/libc/string/strlcpy.c (limited to 'lib/libc/string/strlcpy.c') 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 + +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; +} -- cgit v1.2.3