* [PATCH] PARAM 1/4: strcspn
@ 2002-11-15 22:14 Rusty Russell
2002-11-15 22:45 ` Jeff Garzik
2002-11-16 0:25 ` Olaf Dietsche
0 siblings, 2 replies; 3+ messages in thread
From: Rusty Russell @ 2002-11-15 22:14 UTC (permalink / raw)
To: torvalds; +Cc: linux-kernel
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.
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .17889-2.5.36-param.pre/include/linux/string.h .17889-2.5.36-param/include/linux/string.h
--- .17889-2.5.36-param.pre/include/linux/string.h 2002-06-06 21:38:40.000000000 +1000
+++ .17889-2.5.36-param/include/linux/string.h 2002-09-19 16:15:20.000000000 +1000
@@ -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
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .17889-2.5.36-param.pre/lib/string.c .17889-2.5.36-param/lib/string.c
--- .17889-2.5.36-param.pre/lib/string.c 2002-05-24 15:20:35.000000000 +1000
+++ .17889-2.5.36-param/lib/string.c 2002-09-19 16:15:20.000000000 +1000
@@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PARAM 1/4: strcspn
2002-11-15 22:14 [PATCH] PARAM 1/4: strcspn Rusty Russell
@ 2002-11-15 22:45 ` Jeff Garzik
2002-11-16 0:25 ` Olaf Dietsche
1 sibling, 0 replies; 3+ messages in thread
From: Jeff Garzik @ 2002-11-15 22:45 UTC (permalink / raw)
To: Rusty Russell; +Cc: torvalds, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PARAM 1/4: strcspn
2002-11-15 22:14 [PATCH] PARAM 1/4: strcspn Rusty Russell
2002-11-15 22:45 ` Jeff Garzik
@ 2002-11-16 0:25 ` Olaf Dietsche
1 sibling, 0 replies; 3+ messages in thread
From: Olaf Dietsche @ 2002-11-16 0:25 UTC (permalink / raw)
To: Rusty Russell; +Cc: torvalds, linux-kernel
Rusty Russell <rusty@rustcorp.com.au> writes:
> +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;
> +}
How about "return p - s;" instead of "count"?
Regards, Olaf.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-11-16 0:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-15 22:14 [PATCH] PARAM 1/4: strcspn Rusty Russell
2002-11-15 22:45 ` Jeff Garzik
2002-11-16 0:25 ` Olaf Dietsche
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox