From 66289aa8ecfa07b20bad424eb9860b196641ef52 Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Fri, 19 Mar 2021 10:54:25 -0500 Subject: first commit --- src/kernel/libs/libc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/kernel/libs/libc.c (limited to 'src/kernel/libs/libc.c') diff --git a/src/kernel/libs/libc.c b/src/kernel/libs/libc.c new file mode 100644 index 0000000..31580ff --- /dev/null +++ b/src/kernel/libs/libc.c @@ -0,0 +1,47 @@ +#include +#include +//#include +// you need to sort all these into diffrent files! TODO +int strncmp(const char *s1, const char *s2, unsigned int n) { + int i; + for(i = 0; ((i <= n) && (s1[i] != '\0') && (s2[i] != '\0')); i++) { + if(s1[i] != s2[i]) { + return(s1[i] - s2[i]); + } + } + return(s1[i] - s2[i]); +} + +int strcmp(const char *s1, const char *s2) { + int i; + for(i = 0; ((s1[i] != '\0') && (s2[i] != '\0')); i++) { + if(s1[i] != s2[i]) { + return(s1[i] - s2[i]); + } + } + return(s1[i] - s2[i]); +} + +int memcmp(const void *s1, const void *s2, size_t n) { + const unsigned char *p1 = s1; // Why is c such a bitch? + const unsigned char *p2 = s2; + int i; + for(i = 0; i < n; i++) { + if(p1[i] != p2[i]) { + return(p1[i] - p2[i]); + } + } + return(p1[n-1] - p2[n-1]); +} + +void strcpy(char *dest, char *src) { + for(unsigned int i = 0; src[i] != '\0'; i++){ + dest[i] = src[i]; + } +} + +void memcpy(char *dest, char *src, size_t n) { + for(unsigned int i = 0; i <= n; i++) { + dest[i] = src[i]; + } +} -- cgit v1.2.3