]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
string: Add strchrnul()
authorSimon Glass <sjg@chromium.org>
Fri, 19 May 2017 02:09:28 +0000 (20:09 -0600)
committerSimon Glass <sjg@chromium.org>
Thu, 1 Jun 2017 13:03:12 +0000 (07:03 -0600)
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@chromium.org>
include/linux/string.h
lib/string.c

index 091ccab395b96e2d582c0ed405d3aef95da9e6db..718c3720a12be743a08bd4087f921b9faa5f797e 100644 (file)
@@ -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
index e94021c4680a118aed754662eb2bf2f0b2e50d4a..e6e749b80b208ed8889dbb226433687e3905054f 100644 (file)
@@ -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