summaryrefslogtreecommitdiff
path: root/src/kernel/libc.c
diff options
context:
space:
mode:
authorBrett Weiland <brett_weiland@bpcspace.com>2021-08-24 14:09:29 -0500
committerBrett Weiland <brett_weiland@bpcspace.com>2021-08-24 14:09:29 -0500
commit9b22a6965579ea1867aea291d910c96f386b518b (patch)
treed06dbb9c4708f1cc713bcb115b32ff9bce4cf9b9 /src/kernel/libc.c
parentbad4b0e9bdfee336bfc1c23761408279eaec1558 (diff)
major backup 8.24.21
Diffstat (limited to 'src/kernel/libc.c')
-rw-r--r--src/kernel/libc.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/kernel/libc.c b/src/kernel/libc.c
index c786cd0..4278281 100644
--- a/src/kernel/libc.c
+++ b/src/kernel/libc.c
@@ -3,7 +3,7 @@
// TODO clean up variable names
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++) {
+ for(i = 0; ((i < (n - 1)) && (s1[i] != '\0') && (s2[i] != '\0')); i++) {
if(s1[i] != s2[i]) {
return(s1[i] - s2[i]);
}
@@ -11,6 +11,13 @@ int strncmp(const char *s1, const char *s2, unsigned int n) {
return(s1[i] - s2[i]);
}
+//this one hasn't been tested
+size_t strlen(const char *s) {
+ size_t len = 0;
+ while(s[len + 1] != '\0') len++;
+ return(len);
+}
+
int strcmp(const char *s1, const char *s2) {
int i;
for(i = 0; ((s1[i] != '\0') && (s2[i] != '\0')); i++) {
@@ -25,7 +32,7 @@ int memcmp(const void *s1, const void *s2, size_t n) {
const unsigned char *p1 = s1;
const unsigned char *p2 = s2;
int i;
- for(i = 0; i < n; i++) {
+ for(i = 0; i < n - 1; i++) {
if(p1[i] != p2[i]) {
return(p1[i] - p2[i]);
}
@@ -41,7 +48,7 @@ void strcpy(char *dest, char *src) {
void *memcpy(void *dest, char *src, size_t n) {
char *p = dest;
- for(unsigned int i = 0; i <= n; i++) {
+ for(unsigned int i = 0; i < n; i++) {
p[i] = src[i];
}
return(dest);
@@ -56,12 +63,16 @@ void *bzero(void *dest, size_t size) {
}
//TODO move this function to a seperate math library
-unsigned int ceil(double n) {
+int ceil(double n) {
int low_n = (int)n;
if(n == (double)low_n) return(low_n);
return(low_n + 1);
}
+int round(double n) {
+ return(int)(n + 0.5);
+}
+
void *memset(void *s, char c, size_t n) {
char *p = s;
for(size_t i = 0; i < n; i++) {