LibC: Implement strsep()

This commit is contained in:
Linus Groh 2022-01-10 21:44:44 +01:00
parent 78fa430ca1
commit 471b798eb0
2 changed files with 18 additions and 0 deletions

View file

@ -448,6 +448,23 @@ size_t strxfrm(char* dest, const char* src, size_t n)
return i;
}
// Not in POSIX, originated in BSD but also supported on Linux.
// https://man.openbsd.org/strsep.3
char* strsep(char** str, char const* delim)
{
if (*str == nullptr)
return nullptr;
auto* begin = *str;
auto* end = begin + strcspn(begin, delim);
if (*end) {
*end = '\0';
*str = ++end;
} else {
*str = nullptr;
}
return begin;
}
void explicit_bzero(void* ptr, size_t size)
{
secure_zero(ptr, size);

View file

@ -59,5 +59,6 @@ char* strtok_r(char* str, const char* delim, char** saved_str);
char* strtok(char* str, const char* delim);
int strcoll(const char* s1, const char* s2);
size_t strxfrm(char* dest, const char* src, size_t n);
char* strsep(char** str, char const* delim);
__END_DECLS