[U-Boot] [PATCH v2 38/71] string: Add strchrnul()
Simon Glass
sjg at chromium.org
Wed May 10 14:21:17 UTC 2017
This functions works like strchr() but returns the end of the string if
the character is not found. Add an implementation of this.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v2: None
include/linux/string.h | 13 +++++++++++++
lib/string.c | 8 ++++++++
2 files changed, 21 insertions(+)
diff --git a/include/linux/string.h b/include/linux/string.h
index 091ccab395..718c3720a1 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -50,6 +50,19 @@ extern int strncasecmp(const char *s1, const char *s2, __kernel_size_t len);
#ifndef __HAVE_ARCH_STRCHR
extern char * strchr(const char *,int);
#endif
+
+/**
+ * strchrnul() - return position of a character in the string, or end of string
+ *
+ * The strchrnul() function is like strchr() except that if c is not found
+ * in s, then it returns a pointer to the nul byte at the end of s, rather than
+ * NULL
+ * @s: string to search
+ * @c: character to search for
+ * @return position of @c in @s, or end of @s if not found
+ */
+const char *strchrnul(const char *s, int c);
+
#ifndef __HAVE_ARCH_STRRCHR
extern char * strrchr(const char *,int);
#endif
diff --git a/lib/string.c b/lib/string.c
index c1a28c14ce..d1ff94dc64 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -230,6 +230,14 @@ char * strchr(const char * s, int c)
}
#endif
+const char *strchrnul(const char *s, int c)
+{
+ for (; *s != (char)c; ++s)
+ if (*s == '\0')
+ break;
+ return s;
+}
+
#ifndef __HAVE_ARCH_STRRCHR
/**
* strrchr - Find the last occurrence of a character in a string
--
2.13.0.rc2.291.g57267f2277-goog
More information about the U-Boot
mailing list