From e8052496519f347e7c2e15147eae329fc40e2e44 Mon Sep 17 00:00:00 2001 From: NAKAMURA Gou Date: Thu, 26 Nov 2015 20:07:26 +0900 Subject: [PATCH] add strrchr() --- lib/include/string.h | 1 + lib/string.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/include/string.h b/lib/include/string.h index e43a4179..0b1bb490 100644 --- a/lib/include/string.h +++ b/lib/include/string.h @@ -23,6 +23,7 @@ int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, size_t n); char *strstr(const char *haystack, const char *needle); char *strchr(const char *s, int n); +char *strrchr(const char *s, int n); void *memcpy(void *dest, const void *src, size_t n); void *memcpy_long(void *dest, const void *src, size_t n); int memcmp(const void *s1, const void *s2, size_t n); diff --git a/lib/string.c b/lib/string.c index 624e390a..010b9c53 100644 --- a/lib/string.c +++ b/lib/string.c @@ -95,7 +95,20 @@ char *strchr(const char *s, int n) { } return NULL; } - + +char * +strrchr(const char *s, int c) +{ + const char *last = NULL; + + do { + if (*s == c) { + last = s; + } + } while (*(s++)); + + return (char *)last; +} /* strrchr() */ char *strstr(const char *haystack, const char *needle) {