init commit

This commit is contained in:
Faynot
2026-07-07 20:35:07 +03:00
commit 38cc34a6e9
33 changed files with 659 additions and 0 deletions

11
src/string/memcmp.c Normal file
View File

@@ -0,0 +1,11 @@
#include <string.h>
int memcmp(const void *vl, const void *vr, size_t n)
{
const unsigned char *l = vl, *r = vr;
for (size_t i = 0; i < n; i++) {
if (l[i] != r[i])
return l[i] - r[i];
}
return 0;
}

10
src/string/memcpy.c Normal file
View File

@@ -0,0 +1,10 @@
#include <string.h>
void *memcpy(void *restrict dest, const void *restrict src, size_t n)
{
unsigned char *d = dest;
const unsigned char *s = src;
for (size_t i = 0; i < n; i++)
d[i] = s[i];
return dest;
}

9
src/string/memset.c Normal file
View File

@@ -0,0 +1,9 @@
#include <string.h>
void *memset(void *dest, int c, size_t n)
{
unsigned char *d = dest;
for (size_t i = 0; i < n; i++)
d[i] = (unsigned char)c;
return dest;
}

7
src/string/strcmp.c Normal file
View File

@@ -0,0 +1,7 @@
#include <string.h>
int strcmp(const char *l, const char *r)
{
while (*l && *l == *r) l++, r++;
return *(unsigned char *)l - *(unsigned char *)r;
}

8
src/string/strlen.c Normal file
View File

@@ -0,0 +1,8 @@
#include <string.h>
size_t strlen(const char *s)
{
const char *p = s;
while (*p) p++;
return p - s;
}