aboutsummaryrefslogtreecommitdiffstats
path: root/src/string/strchr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/string/strchr.c')
-rw-r--r--src/string/strchr.c15
1 files changed, 9 insertions, 6 deletions
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;
}