← board

crtl: strtok not implemented (undeclared function)

Problem

#include <string.h>
char src[] = "hello,world,foo";
char *tok = strtok(src, ",");

fails with call to undeclared function: strtok. lib/crtl/src/string.c has strcat/strchr/strcpy/strerror/strncat/strncpy/strpbrk/strrchr/strstr/memcmp/ strcmp/strcoll/strncmp/strcspn/strlen/strspn/strxfrm/memchr/memcpy/memmove/ memsetstrtok (and strtok_r) are the only common string.h functions missing from that set.

Why it matters

strtok is one of the most commonly reached-for string.h functions for tokenizing (config parsing, CSV-ish splitting, simple protocol lines). Its absence will silently wall off any C program that uses it, with no earlier warning since everything else in string.h works.

Scope

Acceptance

char src[] = "hello,world,foo";
char *tok = strtok(src, ",");
while (tok) { printf("[%s]", tok); tok = strtok(NULL, ","); }

prints [hello][world][foo].

Log

RESOLVED 2026-07-07 (Track B)

Implemented strtok + strtok_r in lib/crtl/src/string.c (decls in string.h), built on the existing strspn/strcspn: strtok_r skips leading delimiters, NUL-terminates the token in place, advances the save-pointer; strtok wraps it over a static save-pointer. Standard semantics (empty fields between adjacent delimiters skipped; NULL first arg continues). Regression b181 (comma/space/ adjacent-delimiter tokenizing + in-place NUL). make test + lua green.