v2 initial commit
This commit is contained in:
parent
2c97dba9f7
commit
d2ef885e8d
118 changed files with 2420 additions and 9320 deletions
37
lib/string.c
37
lib/string.c
|
|
@ -1,7 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/slab.h>
|
||||
#include <kernel/lock.h>
|
||||
|
||||
#include <lib/string.h>
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t num)
|
||||
|
|
@ -161,37 +158,3 @@ bool strempty(const char *s)
|
|||
return true;
|
||||
}
|
||||
|
||||
char **strsplit(const char *s, char delim, int *n)
|
||||
{
|
||||
int num = 0;
|
||||
for (int i = 0; s[i]; i++) {
|
||||
if (s[i] == delim)
|
||||
num++;
|
||||
}
|
||||
|
||||
char **ret = kmalloc((num + 2) * sizeof(char *), ALLOC_KERN);
|
||||
int idx = 0;
|
||||
int last = 0;
|
||||
for (int i = 0; s[i]; i++) {
|
||||
if (s[i] == delim) {
|
||||
ret[idx] = kmalloc(i - last + 1, ALLOC_KERN);
|
||||
memcpy(ret[idx], s + last, i - last);
|
||||
ret[idx][i - last] = 0;
|
||||
idx++;
|
||||
last = i + 1;
|
||||
|
||||
if(ret[idx - 1][0] == 0) {
|
||||
kfree(ret[idx - 1]);
|
||||
idx--;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret[idx] = kmalloc(strlen(s) - last + 1, ALLOC_KERN);
|
||||
memcpy(ret[idx], s + last, strlen(s) - last);
|
||||
ret[idx][strlen(s) - last] = 0;
|
||||
idx++;
|
||||
ret[idx] = NULL;
|
||||
if (n)
|
||||
*n = idx;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue