Name n3667, alx-0038r1 - add strsep(), wcssep() Principles - Codify existing practice to address evident deficiencies. - Enable secure programming Category Standardize libc APIs Author Alejandro Colomar History r0 (2025-07-01): - Initial draft. r1 (2025-07-27; n3667): - Add note about DoS. Rationale strsep(3) is an API from GNU and BSD which is easier to use than strtok(3), as it holds no state. It has slightly different semantics from strtok(3), though. strsep(3) doesn't skip empty fields. strtok(3) skips empty fields, which in some cases might be desired, but often it isn't. DoS concerns While one may be concerned that these APIs may promote DoS attacks by searching in a loop within a loop, these APIs are designed to be used with (short) string literals as the second argument. It would only be a concern if the second argument can be controlled by a user, but that would be unusual. Prior art This API is widely available in BSD and GNU systems, and it first appeared in 4.4BSD. Proposed wording Based on N3550. 7.28.5 String handling :: Search functions ## New subsection after 7.28.5.9 ("The strtok function") +7.28.5.9+1 The strsep function + +Synopsis +1 + #include + char *strsep(char **restrict sp, const char *restrict delim); + +Description +2 + The strsep function + locates the first occurence + in the string pointed to by *sp + of any character + from the string pointed to by delim. + If such a character is found, + the function overwrites it with a null character. + +3 + The value *sp is updated + to point to one past the overwritten character, + or set to a null pointer + if no character from delim occurs in *sp. + +Returns +3 + The stpsep function + returns *sp. 7.33.4.6 General wide string utilities :: Wide string search functions ## New section after 7.33.4.6.8 ("The wcstok function") +7.33.4.6.8+1 The wcssep function + +Synopsis +1 + #include + wchar_t *wcssep(wchar_t **restrict sp, const wchar_t *restrict delim); + +Description +2 + The wcssep function + is equivalent to strsep + except that it handles wide strings.