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)
{
char *strtok_last = NULL;
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 *last = *llast;
if (str)
last = str;
(*llast) = str;
if (!last)
if (!(*llast))
return NULL;
char *ret = last;
while (*last) {
if (strchr(delim, *last)) {
*last = 0;
last++;
char *ret = (*llast);
while (*(*llast)) {
if (strchr(delim, *(*llast))) {
*(*llast) = 0;
(*llast)++;
return ret;
}
last++;
(*llast)++;
}
return ret;