summaryrefslogtreecommitdiffstats
path: root/usr/klibc/strlcpy.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/klibc/strlcpy.c')
-rw-r--r--usr/klibc/strlcpy.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/usr/klibc/strlcpy.c b/usr/klibc/strlcpy.c
new file mode 100644
index 0000000..51c72d8
--- /dev/null
+++ b/usr/klibc/strlcpy.c
@@ -0,0 +1,27 @@
+/*
+ * strlcpy.c
+ */
+
+#include <string.h>
+#include <klibc/compiler.h>
+
+size_t strlcpy(char *dst, const char *src, size_t size)
+{
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
+
+ while ((ch = *p++)) {
+ if (bytes + 1 < size)
+ *q++ = ch;
+
+ bytes++;
+ }
+
+ /* If size == 0 there is no space for a final null... */
+ if (size)
+ *q = '\0';
+
+ return bytes;
+}