diff --git a/lib/libc/minimal/include/string.h b/lib/libc/minimal/include/string.h index 0b97c0fe39c..3ef8c512d75 100644 --- a/lib/libc/minimal/include/string.h +++ b/lib/libc/minimal/include/string.h @@ -29,6 +29,7 @@ extern "C" { extern char *strcpy(char *_Restrict d, const char *_Restrict s); extern char *strncpy(char *_Restrict d, const char *_Restrict s, size_t n); extern char *strchr(const char *s, int c); +extern char *strrchr(const char *s, int c); extern size_t strlen(const char *s); extern int strcmp(const char *s1, const char *s2); extern int strncmp(const char *s1, const char *s2, size_t n); diff --git a/lib/libc/minimal/source/string/string.c b/lib/libc/minimal/source/string/string.c index 7a18e1a609a..793c10bf222 100644 --- a/lib/libc/minimal/source/string/string.c +++ b/lib/libc/minimal/source/string/string.c @@ -84,6 +84,26 @@ char *strchr(const char *s, int c) return (*s == tmp) ? (char *) s : NULL; } +/** + * + * @brief String scanning operation + * + * @return pointer to last instance of found byte, or NULL if not found + */ + +char *strrchr(const char *s, int c) +{ + char *match = NULL; + + do { + if (*s == (char)c) { + match = (char *)s; + } + } while (*s++); + + return match; +} + /** * * @brief Get string length