implement memcmp
This commit is contained in:
parent
3f258485b9
commit
8cf50c9a6e
12
core/klibc.c
12
core/klibc.c
@ -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;
|
||||||
|
@ -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);
|
||||||
|
@ -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)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user