forked from Bananymous/banan-os
Initial commit. We have a booting kernel
This commit is contained in:
17
libc/string/memcmp.c
Normal file
17
libc/string/memcmp.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <string.h>
|
||||
|
||||
int memcmp(const void* s1, const void* s2, size_t n)
|
||||
{
|
||||
const unsigned char* a = s1;
|
||||
const unsigned char* b = s2;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
if (*a != *b)
|
||||
return *a - *b;
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
libc/string/memcpy.c
Normal file
10
libc/string/memcpy.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <string.h>
|
||||
|
||||
void* memcpy(void* restrict destp, const void* restrict srcp, size_t n)
|
||||
{
|
||||
unsigned char* dest = (unsigned char*)destp;
|
||||
const unsigned char* src = (const unsigned char*)srcp;
|
||||
for (size_t i = 0; i < n; i++)
|
||||
dest[i] = src[i];
|
||||
return destp;
|
||||
}
|
||||
20
libc/string/memmove.c
Normal file
20
libc/string/memmove.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <string.h>
|
||||
|
||||
void* memmove(void* destp, const void* srcp, size_t n)
|
||||
{
|
||||
unsigned char* dest = (unsigned char*)destp;
|
||||
const unsigned char* src = (const unsigned char*)srcp;
|
||||
|
||||
if (dest < src)
|
||||
{
|
||||
for (size_t i = 0; i < n; i++)
|
||||
dest[i] = src[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 1; i <= n; i++)
|
||||
dest[n - i] = src[n - i];
|
||||
}
|
||||
|
||||
return destp;
|
||||
}
|
||||
9
libc/string/memset.c
Normal file
9
libc/string/memset.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <string.h>
|
||||
|
||||
void* memset(void* s, int c, size_t n)
|
||||
{
|
||||
unsigned char* p = (unsigned char*)s;
|
||||
for (size_t i = 0; i < n; i++)
|
||||
p[i] = c;
|
||||
return s;
|
||||
}
|
||||
9
libc/string/strlen.c
Normal file
9
libc/string/strlen.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <string.h>
|
||||
|
||||
size_t strlen(const char* str)
|
||||
{
|
||||
size_t len = 0;
|
||||
while (str[len])
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
Reference in New Issue
Block a user