refining vfs

This commit is contained in:
2026-07-10 07:46:46 -05:00
parent 4d98d73f5e
commit 032a35206a
13 changed files with 304 additions and 277 deletions

View File

@@ -2,48 +2,63 @@
#include <stddef.h>
static int is_delim(char c, const char* delim) {
while (*delim) {
if (c == *delim) {
return 1;
char* strtok_r(char *s, const char *delim, char **saveptr) {
char *token;
if (!saveptr) {
return NULL;
}
if (!s) {
s = *saveptr;
}
if (!s || *s == '\0') {
*saveptr = s;
return NULL;
}
while (*s != '\0') {
const char *d = delim;
int is_delim = 0;
while (*d != '\0') {
if (*s == *d) {
is_delim = 1;
break;
}
d++;
}
delim++;
}
return 0;
}
char* strtok_r(char* str, const char* delim, char** saveptr) {
if (saveptr == NULL) {
return NULL;
}
char* next_token = (str != NULL) ? str : *saveptr;
if (next_token == NULL || *next_token == '\0') {
*saveptr = NULL;
return NULL;
}
while (*next_token && is_delim(*next_token, delim)) {
next_token++;
}
if (*next_token == '\0') {
*saveptr = next_token;
return NULL;
}
char* token_start = next_token;
while (*next_token) {
if (is_delim(*next_token, delim)) {
*next_token = '\0'; // Destructively null-terminate the token
*saveptr = next_token + 1; // Save the position right after the null-terminator
return token_start;
if (!is_delim) {
break;
}
next_token++;
s++;
}
*saveptr = next_token;
return token_start;
if (*s == '\0') {
*saveptr = s;
return NULL;
}
token = s;
while (*s != '\0') {
const char *d = delim;
int is_delim = 0;
while (*d != '\0') {
if (*s == *d) {
is_delim = 1;
break;
}
d++;
}
if (is_delim) {
*s = '\0';
*saveptr = s + 1;
return token;
}
s++;
}
*saveptr = s;
return token;
}