From e2d52adc78d14ba3d2c6a6017798c704a2ffb4c5 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 1 Sep 2015 06:03:04 +0200 Subject: add strstr functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/string/strchr.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/string/strchr.c') diff --git a/src/string/strchr.c b/src/string/strchr.c index 6a25f78..21345d4 100644 --- a/src/string/strchr.c +++ b/src/string/strchr.c @@ -93,10 +93,11 @@ void* memrchr(const void* segment, int c, size_t size) */ char* strchr(const char* string, int c) { - while (; *string; string++) + for (;;) if (*string == c) return string; - return NULL; + else if (!*string++) + return NULL; } /* TODO Ensure that `s = strchr(s, 0)` is faster than `s = s + strlen(s)`. */ @@ -117,10 +118,11 @@ char* strchr(const char* string, int c) */ char* strchrnul(const char* string, int c) { - while (; *string; string++) + for (;; string++) if (*string == c) return string; - return string; + else if (!*string) + return string; } @@ -141,9 +143,10 @@ char* strchrnul(const char* string, int c) char* strrchr(const char* string, int c) { char* r = NULL; - while (; *string; string++) + for (;;) if (*string == c) r = string; - return r; + else if (!*string++) + return r; } -- cgit v1.2.3-70-g09d2