Wrote strlen() and strcpy()
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
noinst_PROGRAMS = quark-kernel
|
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_LDADD = -lgcc
|
||||||
quark_kernel_CPPFLAGS = -ffreestanding -mgeneral-regs-only -O0 -Wall -fno-exceptions -fno-rtti -ggdb
|
quark_kernel_CPPFLAGS = -ffreestanding -mgeneral-regs-only -O0 -Wall -fno-exceptions -fno-rtti -ggdb
|
||||||
quark_kernel_LDFLAGS = -nostdlib
|
quark_kernel_LDFLAGS = -nostdlib
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "elf.hpp"
|
#include "module.hpp"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
|
||||||
kernel::ELF::ELF()
|
kernel::ELF::ELF()
|
||||||
|
|||||||
47
src/util.cpp
47
src/util.cpp
@@ -64,7 +64,7 @@ int memcmp(const void* ptr1, const void* ptr2, size_t num)
|
|||||||
return 0;
|
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* dest = (uint8_t*) ptr;
|
||||||
uint8_t v = (uint8_t) value;
|
uint8_t v = (uint8_t) value;
|
||||||
@@ -75,6 +75,51 @@ void* memset (void* ptr, int value, size_t num)
|
|||||||
return ptr;
|
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()
|
void __cxa_pure_virtual()
|
||||||
{
|
{
|
||||||
// do nothing
|
// 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" 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
|
#endif
|
||||||
Reference in New Issue
Block a user