summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2017-05-19 02:09:29 (GMT)
committerSimon Glass <sjg@chromium.org>2017-06-01 13:03:12 (GMT)
commita7d0021063661a65bfa47d4ec912da4e2cfa8f9a (patch)
treec4f46f6084a9f3b9ca3795d68195a9ed11274f66 /lib
parent6b45ba45fbcd1acc11c88ee1c15ed5fcb49f9e32 (diff)
downloadu-boot-a7d0021063661a65bfa47d4ec912da4e2cfa8f9a.tar.xz
string: Add strcspn()
Add an implementation of strcspn() which returns the number of initial characters that do not match any in a rejection list. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c
index e6e749b..c4ca944 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -286,6 +286,30 @@ size_t strnlen(const char * s, size_t count)
}
#endif
+#ifndef __HAVE_ARCH_STRCSPN
+/**
+ * strcspn - Calculate the length of the initial substring of @s which does
+ * not contain letters in @reject
+ * @s: The string to be searched
+ * @reject: The string to avoid
+ */
+size_t strcspn(const char *s, const char *reject)
+{
+ const char *p;
+ const char *r;
+ size_t count = 0;
+
+ for (p = s; *p != '\0'; ++p) {
+ for (r = reject; *r != '\0'; ++r) {
+ if (*p == *r)
+ return count;
+ }
+ ++count;
+ }
+ return count;
+}
+#endif
+
#ifndef __HAVE_ARCH_STRDUP
char * strdup(const char *s)
{