implement memcmp

This commit is contained in:
Mathieu Maret 2019-04-15 23:19:14 +02:00
parent 3f258485b9
commit 8cf50c9a6e
3 changed files with 14 additions and 1 deletions

View File

@ -1,5 +1,17 @@
#include "klibc.h" #include "klibc.h"
int memcmp(const void* aptr, const void* bptr, size_t size) {
const unsigned char* a = (const unsigned char*) aptr;
const unsigned char* b = (const unsigned char*) bptr;
for (size_t i = 0; i < size; i++) {
if (a[i] < b[i])
return -1;
else if (b[i] < a[i])
return 1;
}
return 0;
}
void *memcpy(void *dst, const void *src, size_t n) void *memcpy(void *dst, const void *src, size_t n)
{ {
char *dstChar = dst; char *dstChar = dst;

View File

@ -9,6 +9,7 @@
((c) == '\r') || ((c) == '\v')) ((c) == '\r') || ((c) == '\v'))
#define isprint(c) ((' ' <= (c)) && ((c) <= '~')) #define isprint(c) ((' ' <= (c)) && ((c) <= '~'))
int memcmp(const void *s1, const void *s2, size_t n);
void *memcpy(void *dest, const void *src, size_t n); void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n); void *memset(void *s, int c, size_t n);
char *itoa(int value, char *str, int base); char *itoa(int value, char *str, int base);

View File

@ -38,7 +38,7 @@ void kmain(unsigned long magic, unsigned long addr)
irqSetup(); irqSetup();
pitSetup(100); pitSetup(100);
if (magic == MULTIBOOT_BOOTLOADER_MAGIC) { // Get loaded by Grub wuth mutliboot version 1 if (magic == MULTIBOOT_BOOTLOADER_MAGIC) { // Get loaded by Grub with mutliboot version 1
multiboot_info_t *mbi = (multiboot_info_t *)addr; multiboot_info_t *mbi = (multiboot_info_t *)addr;
/* Are mem_* valid? */ /* Are mem_* valid? */
if (CHECK_FLAG(mbi->flags, 0)) { if (CHECK_FLAG(mbi->flags, 0)) {