string.c: rework strtok again

This commit is contained in:
Michael Shaw 2023-10-19 14:20:22 -04:00
commit 9476b3f810
2 changed files with 9 additions and 9 deletions

View file

@ -53,6 +53,7 @@ int read(int fd, void *buf, size_t count)
int open(const char *pathname, int flags) int open(const char *pathname, int flags)
{ {
char *strtok_last = NULL;
return 0; return 0;
} }

View file

@ -122,21 +122,20 @@ char *strchr(const char *s, int c)
char *strtok(char *str, const char *delim, char **llast) char *strtok(char *str, const char *delim, char **llast)
{ {
char *last = *llast;
if (str) if (str)
last = str; (*llast) = str;
if (!last) if (!(*llast))
return NULL; return NULL;
char *ret = last; char *ret = (*llast);
while (*last) { while (*(*llast)) {
if (strchr(delim, *last)) { if (strchr(delim, *(*llast))) {
*last = 0; *(*llast) = 0;
last++; (*llast)++;
return ret; return ret;
} }
last++; (*llast)++;
} }
return ret; return ret;