summaryrefslogtreecommitdiffstats
path: root/kernel/string.c
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-08-02 22:31:56 +0000
committerJoursoir <chat@joursoir.net>2021-08-02 22:31:56 +0000
commitcaa440daf6e7954cc9515fd090beb64b87493eca (patch)
treef86b590b69b5ba0605e18403db0801d880992c14 /kernel/string.c
parent73ba11fe151f6e643f187f3abd22f1fe0fcb743e (diff)
downloadmfsos-caa440daf6e7954cc9515fd090beb64b87493eca.tar.gz
mfsos-caa440daf6e7954cc9515fd090beb64b87493eca.tar.bz2
mfsos-caa440daf6e7954cc9515fd090beb64b87493eca.zip
string: make memcpy(), memset(), memmove()
Diffstat (limited to 'kernel/string.c')
-rw-r--r--kernel/string.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/kernel/string.c b/kernel/string.c
index d038c27..006b907 100644
--- a/kernel/string.c
+++ b/kernel/string.c
@@ -7,3 +7,45 @@ size_t strlen(const char *str)
len++;
return len;
}
+
+/*
+ Copy bytes in memory. If copying takes place between objects
+ that overlap, the behavior is undefined.
+*/
+void *memcpy(void *dest, const void *src, size_t n)
+{
+ size_t i;
+ const char *s = src;
+ char *d = dest;
+
+ for(i = 0; i < n; i++)
+ d[i] = s[i];
+ return dest;
+}
+
+void *memset(void *dest, int c, size_t n)
+{
+ char *d = dest;
+ while(n--)
+ *d++ = c;
+ return dest;
+}
+
+/*
+ Copy bytes in memory with overlapping areas.
+*/
+void *memmove(void *dest, const void *src, size_t n)
+{
+ const char *s = src;
+ char *d = dest;
+
+ if(dest == src)
+ return dest;
+
+ if(dest < src)
+ return memcpy(dest, src, n);
+
+ while(n--)
+ d[n] = s[n];
+ return dest;
+}