ratio submodule
This commit is contained in:
14
libbozo/src/string/memcpy.c
Normal file
14
libbozo/src/string/memcpy.c
Normal 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;
|
||||
}
|
||||
14
libbozo/src/string/strchr.c
Normal file
14
libbozo/src/string/strchr.c
Normal 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;
|
||||
}
|
||||
10
libbozo/src/string/strcmp.c
Normal file
10
libbozo/src/string/strcmp.c
Normal 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];
|
||||
}
|
||||
10
libbozo/src/string/strlen.c
Normal file
10
libbozo/src/string/strlen.c
Normal 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;
|
||||
}
|
||||
12
libbozo/src/string/strncmp.c
Normal file
12
libbozo/src/string/strncmp.c
Normal 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];
|
||||
}
|
||||
18
libbozo/src/string/strstr.c
Normal file
18
libbozo/src/string/strstr.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user