aboutsummaryrefslogtreecommitdiff
path: root/kernel/lib/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/lib/string.c')
-rw-r--r--kernel/lib/string.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/kernel/lib/string.c b/kernel/lib/string.c
index da8f60e..6d26478 100644
--- a/kernel/lib/string.c
+++ b/kernel/lib/string.c
@@ -38,12 +38,12 @@ int strcmp(const char *s1, const char *s2) {
s1++;
s2++;
}
- return (* (unsigned char*)s1 - *(unsigned char*)s2);
+ return (*(unsigned char*)s1 - *(unsigned char*)s2);
}
-void *memcpy(void *vd, const void *vs, int count) {
+void *memcpy(void *vd, const void *vs, size_t count) {
uint8_t *dest = (uint8_t*)vd, *src = (uint8_t*)vs;
- int f = count % 4, n = count / 4, i;
+ size_t f = count % 4, n = count / 4, i;
const uint32_t* s = (uint32_t*)src;
uint32_t* d = (uint32_t*)dest;
for (i = 0; i < n; i++) {
@@ -57,10 +57,31 @@ void *memcpy(void *vd, const void *vs, int count) {
return vd;
}
-void *memset(void *dest, int val, int count) {
+void *memmove(void *vd, const void *vs, size_t count) {
+ uint8_t *dest = (uint8_t*)vd, *src = (uint8_t*)vs;
+
+ if (vd < vs) {
+ for (size_t i = 0; i < count; i++)
+ dest[i] = src[i];
+ } else {
+ for (size_t i = 0; i < count; i++)
+ dest[count - i] = src[count - i];
+ }
+ return vd;
+}
+
+int memcmp(const void *va, const void *vb, size_t count) {
+ uint8_t *a = (uint8_t*)va;
+ uint8_t *b = (uint8_t*)vb;
+ for (size_t i = 0; i < count; i++) {
+ if (a[i] != b[i]) return (int)a[i] - (int)b[i];
+ }
+ return 0;
+}
+
+void *memset(void *dest, int val, size_t count) {
uint8_t *dest_c = (uint8_t*)dest;
- int i;
- for (i = 0; i < count; i++) {
+ for (size_t i = 0; i < count; i++) {
dest_c[i] = val;
}
return dest;