aboutsummaryrefslogtreecommitdiffstats
path: root/memory/stpncpy.c
diff options
context:
space:
mode:
Diffstat (limited to 'memory/stpncpy.c')
-rw-r--r--memory/stpncpy.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/memory/stpncpy.c b/memory/stpncpy.c
new file mode 100644
index 0000000..fa53db7
--- /dev/null
+++ b/memory/stpncpy.c
@@ -0,0 +1,9 @@
+#include "memory.h"
+
+char *stpncpy(char *destination, char const *source, size_t count)
+{
+ char *result = memccpy(destination, source, '\0', count);
+ result = (result == NULL) ? &destination[count] : (result - 1);
+ memset(result, 0, (size_t)(&destination[count] - result));
+ return result;
+}