summaryrefslogtreecommitdiff
path: root/portability/strlcpy.c
diff options
context:
space:
mode:
Diffstat (limited to 'portability/strlcpy.c')
-rw-r--r--portability/strlcpy.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/portability/strlcpy.c b/portability/strlcpy.c
new file mode 100644
index 0000000..6ce46e3
--- /dev/null
+++ b/portability/strlcpy.c
@@ -0,0 +1,13 @@
+#include <stddef.h>
+#include <string.h>
+
+size_t strlcpy(char *dst, const char *src, size_t size)
+{
+ size_t ret = strlen(src), len;
+ if (!size) return ret;
+ len = ret;
+ if (len >= size) len = size - 1;
+ memcpy(dst, src, len);
+ dst[len] = 0;
+ return ret;
+}