commit 4b31904c19ede644b5657f46b5823faf9e2bcf09
parent 4e10af7b640ed86d32998b662f132cc76743b5db
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 17 Feb 2017 08:31:48 +0100
[libc] Add memmove()
Diffstat:
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/libc/src/Makefile b/libc/src/Makefile
@@ -3,7 +3,7 @@
LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
strrchr.o strcat.o strncpy.o strncat.o \
- memset.o memcpy.o
+ memset.o memcpy.o memmove.o
all: libc.a
diff --git a/libc/src/memmove.c b/libc/src/memmove.c
@@ -0,0 +1,19 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+
+void *
+memmove(void *dst, const void *src, size_t n)
+{
+ char *d = dst, *s = (char *) src;
+
+ if (d < s) {
+ while (n-- > 0)
+ *d++ = *s++;
+ } else {
+ s += n-1, d += n-1;
+ while (n-- > 0)
+ *d-- = *s--;
+ }
+ return dst;
+}