1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

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.
This commit is contained in:
Brian Gianforcaro 2021-12-27 19:27:46 -08:00 committed by Andreas Kling
parent c4b1e49036
commit fb8df01036
2 changed files with 15 additions and 0 deletions

View file

@ -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* strchrnul(const char* str, int c)
{ {
char ch = c; char ch = c;
@ -260,6 +266,12 @@ char* strrchr(const char* str, int ch)
return last; 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 // https://pubs.opengroup.org/onlinepubs/9699919799/functions/strcat.html
char* strcat(char* dest, const char* src) char* strcat(char* dest, const char* src)
{ {

View file

@ -38,6 +38,9 @@ char* strchrnul(const char*, int c);
char* strstr(const char* haystack, const char* needle); char* strstr(const char* haystack, const char* needle);
char* strrchr(const char*, int c); 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* strcat(char* dest, const char* src);
char* strncat(char* dest, const char* src, size_t); char* strncat(char* dest, const char* src, size_t);