Commit bbeabef1 authored by Rusty Russell's avatar Rusty Russell Committed by Linus Torvalds

[PATCH] add strcspn() library function

This patch implements a generic strcspn.
parent 66f67a6b
...@@ -15,7 +15,7 @@ extern "C" { ...@@ -15,7 +15,7 @@ extern "C" {
extern char * strpbrk(const char *,const char *); extern char * strpbrk(const char *,const char *);
extern char * strsep(char **,const char *); extern char * strsep(char **,const char *);
extern __kernel_size_t strspn(const char *,const char *); extern __kernel_size_t strspn(const char *,const char *);
extern __kernel_size_t strcspn(const char *,const char *);
/* /*
* Include machine specific inline routines * Include machine specific inline routines
......
...@@ -272,6 +272,29 @@ size_t strspn(const char *s, const char *accept) ...@@ -272,6 +272,29 @@ size_t strspn(const char *s, const char *accept)
} }
#endif #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 #ifndef __HAVE_ARCH_STRPBRK
/** /**
* strpbrk - Find the first occurrence of a set of characters * strpbrk - Find the first occurrence of a set of characters
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment