aboutsummaryrefslogtreecommitdiffstats
path: root/memory/memccpy.c
diff options
context:
space:
mode:
Diffstat (limited to 'memory/memccpy.c')
-rw-r--r--memory/memccpy.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/memory/memccpy.c b/memory/memccpy.c
new file mode 100644
index 0000000..b960b34
--- /dev/null
+++ b/memory/memccpy.c
@@ -0,0 +1,14 @@
+#include "memory.h"
+
+void *memccpy(void *restrict dest, void const *restrict src, int value,
+ size_t count)
+{
+ unsigned char *restrict destination = dest;
+ unsigned char const *restrict source = src;
+ for (size_t i = 0; i < count; i++) {
+ destination[i] = source[i];
+ if (destination[i] == (unsigned char)value)
+ return &destination[i + 1];
+ }
+ return NULL;
+}