summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-12-27 19:27:46 -0800
committerAndreas Kling <kling@serenityos.org>2021-12-28 11:00:51 +0100
commitfb8df01036dc5d2b427f58e13ab819d8ad7235d4 (patch)
tree40d753eb33fd6d24f6c373ec8fa7d04521893dd8 /Userland/Libraries
parentc4b1e490369aa79cd79b79f0c41135244a7186e7 (diff)
downloadserenity-fb8df01036dc5d2b427f58e13ab819d8ad7235d4.zip
LibC: Add rindex() and index() APIs
These POSIX APIs are defined as mapping directly to `strrchr` and `strchr` respectively. These are needed for the latest version of the stress-ng port, and also give us better POSIX compliance.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibC/string.cpp12
-rw-r--r--Userland/Libraries/LibC/string.h3
2 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/string.cpp b/Userland/Libraries/LibC/string.cpp
index 5493f7ac6a..914ad00e5b 100644
--- a/Userland/Libraries/LibC/string.cpp
+++ b/Userland/Libraries/LibC/string.cpp
@@ -227,6 +227,12 @@ char* strchr(const char* str, int c)
}
}
+// https://pubs.opengroup.org/onlinepubs/9699959399/functions/index.html
+char* index(const char* str, int c)
+{
+ return strchr(str, c);
+}
+
char* strchrnul(const char* str, int c)
{
char ch = c;
@@ -260,6 +266,12 @@ char* strrchr(const char* str, int ch)
return last;
}
+// https://pubs.opengroup.org/onlinepubs/9699959399/functions/rindex.html
+char* rindex(const char* str, int ch)
+{
+ return strrchr(str, ch);
+}
+
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/strcat.html
char* strcat(char* dest, const char* src)
{
diff --git a/Userland/Libraries/LibC/string.h b/Userland/Libraries/LibC/string.h
index 6f5c399131..44dabc3e36 100644
--- a/Userland/Libraries/LibC/string.h
+++ b/Userland/Libraries/LibC/string.h
@@ -38,6 +38,9 @@ char* strchrnul(const char*, int c);
char* strstr(const char* haystack, const char* needle);
char* strrchr(const char*, int c);
+char* index(const char* str, int ch);
+char* rindex(const char* str, int ch);
+
char* strcat(char* dest, const char* src);
char* strncat(char* dest, const char* src, size_t);