libluna+libc: Add strtok_r()

This commit is contained in:
apio 2023-05-20 16:37:07 +02:00
parent 47d505dcbb
commit 9bb5371e8c
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 12 additions and 2 deletions

View File

@ -71,6 +71,9 @@ extern "C"
/* Separate a string into several tokens. */
char* strtok(char* str, const char* delim);
/* Separate a string into several tokens. */
char* strtok_r(char* str, const char* delim, char** savep);
/* Return a heap-allocated copy of a fixed-size string. */
char* strndup(const char* str, size_t max);

View File

@ -18,6 +18,7 @@ extern "C"
usize strcspn(const char* str, const char* reject);
char* strtok(char* str, const char* delim);
char* strtok_r(char* str, const char* delim, char** savep);
usize wcslen(const wchar_t* str);
int wcscmp(const wchar_t* a, const wchar_t* b);

View File

@ -219,9 +219,9 @@ extern "C"
return (usize)(s - str);
}
char* strtok(char* str, const char* delim)
char* strtok_r(char* str, const char* delim, char** savep)
{
static char* s = nullptr;
auto& s = *savep;
if (str) s = str;
if (!s) return nullptr;
@ -248,6 +248,12 @@ extern "C"
return nullptr;
}
char* strtok(char* str, const char* delim)
{
static char* s;
return strtok_r(str, delim, &s);
}
char* strpbrk(const char* s, const char* accept)
{
usize index = strcspn(s, accept);