vfs - kinda good vfs implementation
This commit is contained in:
parent
cfc9159ad9
commit
1e84bcedc9
13 changed files with 3650 additions and 12 deletions
|
@ -1,7 +1,10 @@
|
|||
#include <lib/string.h>
|
||||
#include <mm/liballoc/liballoc.h>
|
||||
#include <mm/memop.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static char *olds;
|
||||
|
||||
int strlen(const char *str) {
|
||||
int len = 0;
|
||||
while (str[len])
|
||||
|
@ -78,3 +81,54 @@ char *strncpy(char *dest, const char *src, size_t n) {
|
|||
dest[i] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
#define DICT_LEN 256
|
||||
|
||||
static int *create_delim_dict(char *delim) {
|
||||
int *d = (int *)malloc(sizeof(int) * DICT_LEN);
|
||||
memset((void *)d, 0, sizeof(int) * DICT_LEN);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < strlen(delim); i++) {
|
||||
d[delim[i]] = 1;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
char *strtok(char *str, char *delim) {
|
||||
|
||||
static char *last, *to_free;
|
||||
int *deli_dict = create_delim_dict(delim);
|
||||
|
||||
if (!deli_dict) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (str) {
|
||||
last = (char *)malloc(strlen(str) + 1);
|
||||
if (!last) {
|
||||
free(deli_dict);
|
||||
}
|
||||
to_free = last;
|
||||
strcpy(last, str);
|
||||
}
|
||||
|
||||
while (deli_dict[*last] && *last != '\0') {
|
||||
last++;
|
||||
}
|
||||
str = last;
|
||||
if (*last == '\0') {
|
||||
free(deli_dict);
|
||||
free(to_free);
|
||||
return NULL;
|
||||
}
|
||||
while (*last != '\0' && !deli_dict[*last]) {
|
||||
last++;
|
||||
}
|
||||
|
||||
*last = '\0';
|
||||
last++;
|
||||
|
||||
free(deli_dict);
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -8,4 +8,5 @@ char *strcpy(char *dest, const char *src);
|
|||
char *strrchr(const char *s, int c);
|
||||
int oct2bin(unsigned char *str, int size);
|
||||
char *strdup(const char *str);
|
||||
char *strncpy(char *dest, const char *src, size_t n);
|
||||
char *strncpy(char *dest, const char *src, size_t n);
|
||||
char *strtok(char *str, char *delim);
|
Loading…
Add table
Add a link
Reference in a new issue