reimplmenets the previous iteration with a brand new custom build system
This commit is contained in:
13
libc/string/memcmp.c
Normal file
13
libc/string/memcmp.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <string.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;
|
||||
}
|
9
libc/string/memcpy.c
Normal file
9
libc/string/memcpy.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <string.h>
|
||||
|
||||
void* memcpy(void* restrict dstptr, const void* restrict srcptr, size_t size) {
|
||||
unsigned char* dst = (unsigned char*) dstptr;
|
||||
const unsigned char* src = (const unsigned char*) srcptr;
|
||||
for (size_t i = 0; i < size; i++)
|
||||
dst[i] = src[i];
|
||||
return dstptr;
|
||||
}
|
14
libc/string/memmove.c
Normal file
14
libc/string/memmove.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include <string.h>
|
||||
|
||||
void* memmove(void* dstptr, const void* srcptr, size_t size) {
|
||||
unsigned char* dst = (unsigned char*) dstptr;
|
||||
const unsigned char* src = (const unsigned char*) srcptr;
|
||||
if (dst < src) {
|
||||
for (size_t i = 0; i < size; i++)
|
||||
dst[i] = src[i];
|
||||
} else {
|
||||
for (size_t i = size; i != 0; i--)
|
||||
dst[i-1] = src[i-1];
|
||||
}
|
||||
return dstptr;
|
||||
}
|
8
libc/string/memset.c
Normal file
8
libc/string/memset.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <string.h>
|
||||
|
||||
void* memset(void* bufptr, int value, size_t size) {
|
||||
unsigned char* buf = (unsigned char*) bufptr;
|
||||
for (size_t i = 0; i < size; i++)
|
||||
buf[i] = (unsigned char) value;
|
||||
return bufptr;
|
||||
}
|
8
libc/string/strlen.c
Normal file
8
libc/string/strlen.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <string.h>
|
||||
|
||||
size_t strlen(const char* str) {
|
||||
size_t len = 0;
|
||||
while (str[len])
|
||||
len++;
|
||||
return len;
|
||||
}
|
8
libc/string/strlen.libk.c
Normal file
8
libc/string/strlen.libk.c
Normal file
@ -0,0 +1,8 @@
|
||||
#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