PARAM 1/4: strcspn
Subsystems (2)
PATCH 1/1 PARAM 1/4: strcspn
No changes to previous send. The standard C strcspn function, very useful for parsing.
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: strcspn patch
Author: Rusty Russell
Status: Experimental
D: This patch implements a generic strcspn.
include/linux/string.h +1 -1
@@ -15,7 +15,7 @@ extern "C" {extern char *strpbrk (const char *,const char *);extern char *strsep (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
lib/string.c +23 -0
@@ -272,6 +272,29 @@ size_t strspn(const char *s, const char }#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
Should we assume from $subject that namespace abuse is still occurring?
PARAM is way too generic, and while you may not like MODULE_PARAM or KPARAM or similar, I should hope it's self-evident that "param" i.e. "parameters" can apply to a great many things inside the kernel.
"PARAM" definitely does not suggest to the casual reader "kernel boot command line arguments, or, module arguments"
Jeff
Quoted 6 lines · Rusty Russell
lib/string.c +6
-0+size_t strcspn (const char *s,const char *reject) +{ +const char *p; +const char *r; +size_t count =0 ; +
lib/string.c size_t strspn(const char *s, const char · line 296
Quoted 10 lines
lib/string.c +10
-0+for (p = s; *p !='\0' ; ++p) { +for (r = reject; *r !='\0' ; ++r) { +if (*p == *r) +return count; + } + ++count; + } + +return count; +}
How about "return p - s;" instead of "count"?
Regards, Olaf.