libc.obj: add strtok_s
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 47s
Build system / Build (pull_request) Successful in 17m25s

This commit is contained in:
2026-02-16 23:12:22 +05:00
parent 7505baa105
commit 97e7404c9e
5 changed files with 57 additions and 43 deletions

View File

@@ -0,0 +1,48 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
char* strtok_s(char* s, const char* delim, char** saveptr)
{
const char* spanp;
int c, sc;
char* tok;
if (s == NULL && (s = *saveptr) == NULL)
return (NULL);
/*
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
*/
cont:
c = *s++;
for (spanp = delim; (sc = *spanp++) != 0;) {
if (c == sc)
goto cont;
}
if (c == 0) { /* no non-delimiter characters */
*saveptr = NULL;
return (NULL);
}
tok = s - 1;
/*
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
* Note that delim must have one NUL; we stop if we see that, too.
*/
for (;;) {
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = 0;
*saveptr = s;
return (tok);
}
} while (sc != 0);
}
/* NOTREACHED */
}