aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarvin Borner2019-09-15 13:22:10 +0200
committerMarvin Borner2019-09-15 13:22:10 +0200
commita9ede4d173bcb2a8e3dbd794e1cf6c9c89b4ae88 (patch)
treef49764d0599cfa72fc749ddd8972dbe9249e3e12 /src
parent46fb7adb706bd92c04ea1d578a167cf5dd3f0f16 (diff)
Added memory copy function
Diffstat (limited to 'src')
-rw-r--r--src/memory/memory.c18
-rw-r--r--src/memory/memory.h6
2 files changed, 13 insertions, 11 deletions
diff --git a/src/memory/memory.c b/src/memory/memory.c
index 3524787..f36c0bc 100644
--- a/src/memory/memory.c
+++ b/src/memory/memory.c
@@ -1,16 +1,14 @@
#include "../graphics/vga.h"
-unsigned char *memory_copy(unsigned char *dest, const unsigned char *src, int count) {
- // TODO: Add memory copy function
+void *memory_copy(void *dest, const void *src, size_t count) {
+ const char *sp = (const char *) src;
+ char *dp = (char *) dest;
+ for (; count != 0; count--) *dp++ = *sp++;
+ return dest;
}
-unsigned char *memory_set(unsigned char *dest, unsigned char val, int count) {
- unsigned char *p = dest;
- while (count > 0) {
- if (!*p) break;
- *p = val;
- p++;
- count--;
- }
+void *memory_set(void *dest, char val, size_t count) {
+ char *temp = (char *) dest;
+ for (; count != 0; count--) *temp++ = val;
return dest;
}
diff --git a/src/memory/memory.h b/src/memory/memory.h
index 9e2374d..d605299 100644
--- a/src/memory/memory.h
+++ b/src/memory/memory.h
@@ -1,6 +1,10 @@
#ifndef MELVIX_MEMORY_H
#define MELVIX_MEMORY_H
-unsigned char *memory_set(unsigned char *dest, unsigned char val, int count);
+#include <stddef.h>
+
+void *memory_copy(void *dest, const void *src, size_t count);
+
+void *memory_set(void *dest, char val, size_t count);
#endif