ref: c3502416b37b482d5d80a79e56ce09d714a9270d
parent: bbc024de5b24bf1956e100b890c3d42666f55374
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Feb 17 03:31:48 EST 2017
[libc] Add memmove()
--- 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
--- /dev/null
+++ b/libc/src/memmove.c
@@ -1,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;
+}