ratio submodule

This commit is contained in:
2024-09-07 14:40:46 +02:00
parent 1894987afc
commit d270657fc9
24 changed files with 534 additions and 4 deletions

View File

@ -0,0 +1,14 @@
#include "kprintf.h"
#include <stddef.h>
#include <stdint.h>
void *memcpy(void *dest, const void *src, size_t n)
{
uint16_t *c1 = (uint16_t *)dest;
const uint16_t *c2 = (const uint16_t *)src;
for (size_t i = 0; i < n; i++)
c1[i] = c2[i];
kprintf(0, "c1: %s\n", c1);
return c1;
}

View File

@ -0,0 +1,14 @@
#include <stddef.h>
char *strchr(const char *str, int c)
{
char *start = (char *) str;
while (*start)
{
if (*start == c)
return start;
start++;
}
return NULL;
}

View File

@ -0,0 +1,10 @@
#include <stddef.h>
int strcmp(const char *s1, const char *s2)
{
size_t i = 0;
while (s1[i] == s2[i] && s1[i] != '\0')
i++;
return s1[i] - s2[i];
}

View File

@ -0,0 +1,10 @@
#include <stddef.h>
size_t strlen(const char *str)
{
const char *start = str;
while (*start != '\0')
start++;
return start - str;
}

View File

@ -0,0 +1,12 @@
#include <stddef.h>
int strncmp(const char *s1, const char *s2, size_t n)
{
size_t i = 0;
if (n == 0)
return 0;
while (s1[i] == s2[i] && i < (n - 1))
i++;
return s1[i] - s2[i];
}

View File

@ -0,0 +1,18 @@
#include "string.h"
#include <stddef.h>
char *strstr(const char *haystack, const char *needle)
{
char *start = (char *) haystack;
size_t len;
len = strlen(needle);
while (*start != '\0')
{
if (strncmp(start, needle, len) == 0)
return start;
start++;
}
return NULL;
}