vfs - start making the VFS
This commit is contained in:
parent
8b75d8d5e6
commit
6a77b066e8
8 changed files with 128 additions and 63 deletions
|
@ -1,4 +1,5 @@
|
|||
#include <lib/string.h>
|
||||
#include <mm/liballoc/liballoc.h>
|
||||
#include <stddef.h>
|
||||
|
||||
int strlen(const char *str) {
|
||||
|
@ -16,14 +17,14 @@ int strcmp(const char *s1, const char *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 *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) {
|
||||
|
@ -35,23 +36,36 @@ char *strchr(const char *s, int c) {
|
|||
}
|
||||
|
||||
char *strrchr(const char *s, int c) {
|
||||
const char *p = NULL;
|
||||
const char *p = NULL;
|
||||
|
||||
for (;;) {
|
||||
if (*s == (char)c)
|
||||
p = s;
|
||||
if (*s++ == '\0')
|
||||
return (char *)p;
|
||||
}
|
||||
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;
|
||||
int n = 0;
|
||||
unsigned char *c = str;
|
||||
while (size-- > 0) {
|
||||
n *= 8;
|
||||
n += *c - '0';
|
||||
c++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
char *strdup(const char *str) {
|
||||
if (str == NULL)
|
||||
return NULL;
|
||||
|
||||
int len = strlen(str);
|
||||
char *dup = (char *)malloc(len + 1);
|
||||
if (dup == NULL)
|
||||
return NULL;
|
||||
|
||||
strcpy(dup, str);
|
||||
return dup;
|
||||
}
|
|
@ -5,4 +5,5 @@ 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);
|
||||
int oct2bin(unsigned char *str, int size);
|
||||
char *strdup(const char *str);
|
Loading…
Add table
Add a link
Reference in a new issue