fs: add ramfs
This commit is contained in:
parent
a7c526d2a6
commit
750ffa2e16
13 changed files with 355 additions and 55 deletions
26
lib/string.c
26
lib/string.c
|
|
@ -1,5 +1,6 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/types.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <lib/string.h>
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t num)
|
||||
|
|
@ -28,7 +29,7 @@ int strncmp(const char *a, const char *b, size_t n)
|
|||
for (size_t i = 0; i < n; i++) {
|
||||
if (a[i] != b[i])
|
||||
return a[i] - b[i];
|
||||
if (!a[i])
|
||||
if (!a[i] || !b[i])
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -136,26 +137,37 @@ char *strtok(char *str, const char *delim, char **llast)
|
|||
(*llast)++;
|
||||
}
|
||||
|
||||
if(!(*ret))
|
||||
if (!(*ret))
|
||||
return NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *strdup(const char *s)
|
||||
{
|
||||
size_t len = strlen(s);
|
||||
char *ret = kalloc(len + 1, ALLOC_KERN);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
ret[len] = 0;
|
||||
strcpy(ret, s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool strempty(const char *s)
|
||||
{
|
||||
if(!s)
|
||||
if (!s)
|
||||
return true;
|
||||
|
||||
if(!*s)
|
||||
if (!*s)
|
||||
return true;
|
||||
|
||||
size_t i = strlen(s);
|
||||
while(i--) {
|
||||
if(s[i] != ' ')
|
||||
while (i--) {
|
||||
if (s[i] != ' ')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue