string: add and test strtok (DONE)

This commit is contained in:
Lephenixnoir 2021-05-24 10:25:32 +02:00
parent 3a9a60db78
commit 1e7e2c656b
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 20 additions and 1 deletions

View File

@ -158,6 +158,7 @@ set(SOURCES
src/libc/string/strspn.c
src/libc/string/strstr.c
src/libc/string/strstr_base.c
src/libc/string/strtok.c
src/libc/string/strxfrm.c)
if(vhex-generic IN_LIST TARGET_FOLDERS)

2
STATUS
View File

@ -127,7 +127,7 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested
7.21.5.5 strrchr: DONE
7.21.5.6 strspn: DONE
7.21.5.7 strstr: DONE
! 7.21.5.8 strtok: TODO
7.21.5.8 strtok: DONE
7.21.6.1 memset: DONE
7.21.6.2 strerror: DONE
7.21.6.3 strlen: DONE

18
src/libc/string/strtok.c Normal file
View File

@ -0,0 +1,18 @@
#include <string.h>
char *strtok(char * restrict new_s, char const * restrict separators)
{
static char *s = NULL;
if(new_s) s = new_s;
/* Skip leading delimiters */
s += strspn(s, separators);
if(!*s) return NULL;
/* Skip non-delimiters */
char *token = s;
s += strcspn(s, separators);
*s++ = 0;
return token;
}