2026-06-30 19:26:31 -05:00
|
|
|
#include <lib/string.h>
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2026-07-11 10:33:08 -05:00
|
|
|
static size_t kernel_strspn(const char *s, const char *accept) {
|
|
|
|
|
const char *p;
|
|
|
|
|
const char *a;
|
|
|
|
|
size_t count = 0;
|
2026-06-30 19:26:31 -05:00
|
|
|
|
2026-07-11 10:33:08 -05:00
|
|
|
for (p = s; *p != '\0'; ++p) {
|
|
|
|
|
for (a = accept; *a != '\0'; ++a) {
|
|
|
|
|
if (*p == *a)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (*a == '\0')
|
|
|
|
|
return count;
|
|
|
|
|
++count;
|
2026-06-30 19:26:31 -05:00
|
|
|
}
|
2026-07-11 10:33:08 -05:00
|
|
|
return count;
|
|
|
|
|
}
|
2026-06-30 19:26:31 -05:00
|
|
|
|
2026-07-11 10:33:08 -05:00
|
|
|
static char *kernel_strpbrk(const char *s, const char *accept) {
|
2026-07-10 07:46:46 -05:00
|
|
|
while (*s != '\0') {
|
2026-07-11 10:33:08 -05:00
|
|
|
const char *a = accept;
|
|
|
|
|
while (*a != '\0') {
|
|
|
|
|
if (*s == *a) {
|
|
|
|
|
return (char *)s;
|
2026-07-10 07:46:46 -05:00
|
|
|
}
|
2026-07-11 10:33:08 -05:00
|
|
|
a++;
|
2026-07-10 07:46:46 -05:00
|
|
|
}
|
|
|
|
|
s++;
|
2026-06-30 19:26:31 -05:00
|
|
|
}
|
2026-07-11 10:33:08 -05:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2026-06-30 19:26:31 -05:00
|
|
|
|
2026-07-11 10:33:08 -05:00
|
|
|
char *strtok_r(char *str, const char *delim, char **saveptr) {
|
|
|
|
|
char *token;
|
|
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
|
str = *saveptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (str == NULL || *str == '\0') {
|
|
|
|
|
*saveptr = NULL;
|
2026-06-30 19:26:31 -05:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-11 10:33:08 -05:00
|
|
|
str += kernel_strspn(str, delim);
|
|
|
|
|
if (*str == '\0') {
|
|
|
|
|
*saveptr = NULL;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2026-06-30 19:26:31 -05:00
|
|
|
|
2026-07-11 10:33:08 -05:00
|
|
|
token = str;
|
|
|
|
|
str = kernel_strpbrk(token, delim);
|
|
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
|
*saveptr = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
*str = '\0';
|
|
|
|
|
*saveptr = str + 1;
|
2026-06-30 19:26:31 -05:00
|
|
|
}
|
|
|
|
|
|
2026-07-10 07:46:46 -05:00
|
|
|
return token;
|
2026-06-30 19:26:31 -05:00
|
|
|
}
|