aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2002-11-16 19:22:00 -0800
committerLinus Torvalds <torvalds@home.transmeta.com>2002-11-16 19:22:00 -0800
commitbbeabef1b1bba4a0eb2c8b6ae7418f9ac1331887 (patch)
tree48fcf1afcfebd8bf2c8b90b6ee7e32f15e519ddf /lib
parent66f67a6b1bc034b3bbf7dc2ae96afd6ea68a0454 (diff)
downloadhistory-bbeabef1b1bba4a0eb2c8b6ae7418f9ac1331887.tar.gz
[PATCH] add strcspn() library function
This patch implements a generic strcspn.
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c
index 97aa5eda363195..c4b66913d22878 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -272,6 +272,29 @@ size_t strspn(const char *s, const char *accept)
}
#endif
+/**
+ * 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;
+}
+
#ifndef __HAVE_ARCH_STRPBRK
/**
* strpbrk - Find the first occurrence of a set of characters