WKern
Loading...
Searching...
No Matches
memutil.c
Go to the documentation of this file.
1/*
2WKern - A Bare Metal OS / Kernel I am maKing (For Fun)
3Copyright (C) 2025 Wdboyes13
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#include <mem/kmem.h>
26void Kmemset(void *ptr, unsigned char value, unsigned int num) {
27 unsigned char *p = (unsigned char *)ptr;
28 for (unsigned int i = 0; i < num; i++) {
29 p[i] = value;
30 }
31}
32
38void *Kmemcpy(void *dest, const void *src, unsigned int count) {
39 unsigned char *d = (unsigned char *)dest;
40 const unsigned char *s = (const unsigned char *)src;
41 while (count--) {
42 *d++ = *s++;
43 }
44 return dest;
45}
46
59int Kmemcmp(const void *a, const void *b, size_t n) {
60 const unsigned char *p1 = (const unsigned char *)a;
61 const unsigned char *p2 = (const unsigned char *)b;
62
63 for (size_t i = 0; i < n; i++) {
64 if (p1[i] != p2[i]) {
65 return (int)p1[i] - (int)p2[i];
66 }
67 }
68 return 0;
69}
void Kmemset(void *ptr, unsigned char value, unsigned int num)
Set memory to a value.
Definition memutil.c:26
int Kmemcmp(const void *a, const void *b, size_t n)
Compare memory.
Definition memutil.c:59
void * Kmemcpy(void *dest, const void *src, unsigned int count)
Copy memory.
Definition memutil.c:38