summaryrefslogtreecommitdiff
path: root/lib/stpncpy.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stpncpy.c')
-rw-r--r--lib/stpncpy.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/stpncpy.c b/lib/stpncpy.c
new file mode 100644
index 0000000..4e0def6
--- /dev/null
+++ b/lib/stpncpy.c
@@ -0,0 +1,10 @@
+#include <string.h>
+
+char *stpncpy(char *restrict dest, const char *restrict src, size_t n)
+{
+ char *d = dest;
+ for (; (*d = *src) && n; d++, src++, n--)
+ ;
+ memset(d, 0, n);
+ return d;
+}