From 6c9d16596b587dd249d8d69395e1053fc15e352e Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Fri, 23 Nov 2007 16:42:44 +0000 Subject: [PATCH] [Mini-OS] Add strrchr() Add strrchr(), useful e.g. for grabbing the last part of a xenbus path. Signed-off-by: Samuel Thibault --- include/lib.h | 1 + lib/string.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/lib.h b/include/lib.h index 809c429..1673d88 100644 --- a/include/lib.h +++ b/include/lib.h @@ -87,6 +87,7 @@ void *memset(void *s,int c, size_t count); size_t strnlen(const char *s, size_t count); size_t strlen(const char *s); char *strchr(const char *s, int c); +char *strrchr(const char *s, int c); char *strstr(const char *s1, const char *s2); char * strcat(char * dest, const char * src); char *strdup(const char *s); diff --git a/lib/string.c b/lib/string.c index c52ae43..019c922 100644 --- a/lib/string.c +++ b/lib/string.c @@ -140,6 +140,15 @@ char * strchr(const char * s, int c) return (char *)s; } +char * strrchr(const char * s, int c) +{ + const char *res; + for(; *s != '\0'; ++s) + if (*s == (char) c) + res = s; + return (char *)res; +} + char * strstr(const char * s1,const char * s2) { int l1, l2; -- 2.39.5