summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-06-28 07:19:33 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-06-28 14:50:03 +0200
commit5eb71097bf476954a0da4279b496997ae27e60fa (patch)
tree46f7aa3f301d2b009bac1e1ed8487bbd7e843a45 /lib
parent45bad4394d50034a8cd157b0f01d2807a5dab372 (diff)
downloadbarebox-5eb71097bf476954a0da4279b496997ae27e60fa.tar.gz
barebox-5eb71097bf476954a0da4279b496997ae27e60fa.tar.xz
string: implement strchrnul
We have at least two places opencoding strchrnul, one of them needlessly iterating twice instead of once over the string. Replace both by calling a common single pass implementation. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210628051934.9604-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c
index bad186586f..9aeb1d8830 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -274,6 +274,24 @@ char * _strchr(const char * s, int c)
#endif
EXPORT_SYMBOL(_strchr);
+#ifndef __HAVE_ARCH_STRCHRNUL
+/**
+ * strchrnul - Find and return a character in a string, or end of string
+ * @s: The string to be searched
+ * @c: The character to search for
+ *
+ * Returns pointer to first occurrence of 'c' in s. If c is not found, then
+ * return a pointer to the null byte at the end of s.
+ */
+char *strchrnul(const char *s, int c)
+{
+ while (*s && *s != (char)c)
+ s++;
+ return (char *)s;
+}
+EXPORT_SYMBOL(strchrnul);
+#endif
+
#ifndef __HAVE_ARCH_STRRCHR
/**
* strrchr - Find the last occurrence of a character in a string