aboutsummaryrefslogtreecommitdiff
path: root/strings.c
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-12-31 11:05:33 +0100
committerWojtek Kosior <kwojtus@protonmail.com>2019-12-31 11:05:33 +0100
commit8025e6b92a09fcf584c13fea3f04f2a0be9cbe64 (patch)
tree30437b2b7d19a2b31f52415bc982287335b081b4 /strings.c
parent254e035cc27d5787348849b65619a702ae0d42e3 (diff)
downloadrpi-MMU-example-8025e6b92a09fcf584c13fea3f04f2a0be9cbe64.tar.gz
rpi-MMU-example-8025e6b92a09fcf584c13fea3f04f2a0be9cbe64.zip
add memcpy
Diffstat (limited to 'strings.c')
-rw-r--r--strings.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/strings.c b/strings.c
index 4164467..94cb6ac 100644
--- a/strings.c
+++ b/strings.c
@@ -1,5 +1,3 @@
-#include <stddef.h>
-
#include "strings.h"
void uint32_to_dec(uint32_t number, char buf[10])
@@ -79,3 +77,17 @@ size_t strlen(char string[])
return len;
}
+
+void memcpy(void *dst, void *src, size_t nbytes)
+{
+ size_t iter;
+
+ // copying by word is faster than by byte
+ // copy by word as much as possible
+ for (iter = 0; iter < nbytes / 4; iter++)
+ ((volatile uint32_t*) dst)[iter] = ((uint32_t*) src)[iter];
+
+ // copy the remaining 1, 2 or 3 bytes by byte
+ for (iter *= 4; iter < nbytes; iter++)
+ ((volatile uint8_t*) dst)[iter] = ((uint8_t*) src)[iter];
+}