summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibC/string.cpp17
-rw-r--r--Userland/Libraries/LibC/string.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/string.cpp b/Userland/Libraries/LibC/string.cpp
index 914ad00e5b..20c6bc8294 100644
--- a/Userland/Libraries/LibC/string.cpp
+++ b/Userland/Libraries/LibC/string.cpp
@@ -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);
diff --git a/Userland/Libraries/LibC/string.h b/Userland/Libraries/LibC/string.h
index 71ffb914b2..b1052cf0c4 100644
--- a/Userland/Libraries/LibC/string.h
+++ b/Userland/Libraries/LibC/string.h
@@ -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