Wrote strlen() and strcpy()

This commit is contained in:
2020-11-18 13:36:09 -06:00
parent 29677e0391
commit c601aed9f2
4 changed files with 52 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
noinst_PROGRAMS = quark-kernel
quark_kernel_SOURCES = startup.cpp elf.cpp tty.cpp systeminfo.cpp util.cpp memorymap.cpp pageallocator.cpp allocator.cpp scheduler.cpp
quark_kernel_SOURCES = startup.cpp module.cpp tty.cpp systeminfo.cpp util.cpp memorymap.cpp pageallocator.cpp allocator.cpp scheduler.cpp
quark_kernel_LDADD = -lgcc
quark_kernel_CPPFLAGS = -ffreestanding -mgeneral-regs-only -O0 -Wall -fno-exceptions -fno-rtti -ggdb
quark_kernel_LDFLAGS = -nostdlib

View File

@@ -1,4 +1,4 @@
#include "elf.hpp"
#include "module.hpp"
#include "util.hpp"
kernel::ELF::ELF()

View File

@@ -64,7 +64,7 @@ int memcmp(const void* ptr1, const void* ptr2, size_t num)
return 0;
}
void* memset (void* ptr, int value, size_t num)
void* memset(void* ptr, int value, size_t num)
{
uint8_t* dest = (uint8_t*) ptr;
uint8_t v = (uint8_t) value;
@@ -75,6 +75,51 @@ void* memset (void* ptr, int value, size_t num)
return ptr;
}
int strlen(const char* str)
{
int i = 0;
while(str[i] != '\0')
{
i++;
}
return i;
}
char* strcpy(char* destination, const char* source)
{
int sourceLen = strlen(source);
if((destination <= source) || (destination > (source + sourceLen)))
{
char* d = destination;
const char* s = source;
while(true)
{
*d = *s;
if(*s == '\0')
{
break;
}
else
{
s++;
d++;
}
}
}
else
{
char* d = destination + sourceLen;
const char* s = source + sourceLen;
do
{
*d = *s;
d--;
s--;
} while(d > destination);
}
return destination;
}
void __cxa_pure_virtual()
{
// do nothing

View File

@@ -13,4 +13,8 @@ extern "C" int memcmp(const void* ptr1, const void* ptr2, size_t num);
extern "C" void* memset(void* ptr, int value, size_t num);
extern "C" int strlen(const char* str);
extern "C" char* strcpy(char* destination, const char* source);
#endif