mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-26 03:12:07 -05:00
LibC: Implement strsep()
This commit is contained in:
parent
78fa430ca1
commit
471b798eb0
2 changed files with 18 additions and 0 deletions
|
@ -448,6 +448,23 @@ size_t strxfrm(char* dest, const char* src, size_t n)
|
||||||
return i;
|
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)
|
void explicit_bzero(void* ptr, size_t size)
|
||||||
{
|
{
|
||||||
secure_zero(ptr, size);
|
secure_zero(ptr, size);
|
||||||
|
|
|
@ -59,5 +59,6 @@ char* strtok_r(char* str, const char* delim, char** saved_str);
|
||||||
char* strtok(char* str, const char* delim);
|
char* strtok(char* str, const char* delim);
|
||||||
int strcoll(const char* s1, const char* s2);
|
int strcoll(const char* s1, const char* s2);
|
||||||
size_t strxfrm(char* dest, const char* src, size_t n);
|
size_t strxfrm(char* dest, const char* src, size_t n);
|
||||||
|
char* strsep(char** str, char const* delim);
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
Loading…
Add table
Reference in a new issue