summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-01-10 21:44:44 +0100
committerLinus Groh <mail@linusgroh.de>2022-01-10 23:47:30 +0100
commit471b798eb03b361cf4275db1ce24415d2efd2e7f (patch)
tree8c9d92f1da8148631169288c3580996f56ff94ad /Userland
parent78fa430ca15f286f57a965cd5652b64fb2b86170 (diff)
downloadserenity-471b798eb03b361cf4275db1ce24415d2efd2e7f.zip
LibC: Implement strsep()
Diffstat (limited to 'Userland')
-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