kernel: various changes.
+ kernel: replace sk-hello test executable with a test initramfs + panic: start implementing a proper kernel panic screen + lib: added a new string.h library for string manipulation. + kernel: replace all the strlen implementations with the strlen() function
This commit is contained in:
parent
7fb04f134b
commit
a838d99a5a
19 changed files with 173 additions and 149 deletions
57
kernel/src/lib/string.c
Normal file
57
kernel/src/lib/string.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include <lib/string.h>
|
||||
#include <stddef.h>
|
||||
|
||||
int strlen(const char *str) {
|
||||
int len = 0;
|
||||
while (str[len])
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
while (*s1 && *s1 == *s2) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return *s1 - *s2;
|
||||
}
|
||||
|
||||
char *strcpy(char *dest, const char *src)
|
||||
{
|
||||
if (dest == NULL || src == NULL)
|
||||
return NULL;
|
||||
|
||||
char *temp = dest;
|
||||
while((*dest++ = *src++) != '\0');
|
||||
return temp;
|
||||
}
|
||||
|
||||
char *strchr(const char *s, int c) {
|
||||
while (*s++) {
|
||||
if (*s == c)
|
||||
return (char *)s;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *strrchr(const char *s, int c) {
|
||||
const char *p = NULL;
|
||||
|
||||
for (;;) {
|
||||
if (*s == (char)c)
|
||||
p = s;
|
||||
if (*s++ == '\0')
|
||||
return (char *)p;
|
||||
}
|
||||
}
|
||||
|
||||
int oct2bin(unsigned char *str, int size) {
|
||||
int n = 0;
|
||||
unsigned char *c = str;
|
||||
while (size-- > 0) {
|
||||
n *= 8;
|
||||
n += *c - '0';
|
||||
c++;
|
||||
}
|
||||
return n;
|
||||
}
|
8
kernel/src/lib/string.h
Normal file
8
kernel/src/lib/string.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
int strlen(const char *str);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
char *strchr(const char *s, int c);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strrchr(const char *s, int c);
|
||||
int oct2bin(unsigned char *str, int size);
|
Loading…
Add table
Add a link
Reference in a new issue