Wrote strlen() and strcpy()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "elf.hpp"
|
||||
#include "module.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
kernel::ELF::ELF()
|
||||
|
||||
45
src/util.cpp
45
src/util.cpp
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user