From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Steven Rostedt <srostedt@redhat.com>
Subject: [PATCH v3 2/6] string: add strtok_r to kernel
Date: Thu, 26 Feb 2009 13:54:21 -0500 [thread overview]
Message-ID: <20090226185901.113852600@goodmis.org> (raw)
In-Reply-To: 20090226185419.371469287@goodmis.org
[-- Attachment #1: 0002-string-add-strtok_r-to-kernel.patch --]
[-- Type: text/plain, Size: 2491 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
This patch adds the function strtok_r to the kernel. This acts just like
the strtok_r that is implemented in glibc, but trimmed down.
Note, this is strtok_r and not strtok. The _r version is reentrant,
where as strtok is not, and thus not suitable for the kernel.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
include/linux/string.h | 3 +++
lib/string.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index d18fc19..c5973a5 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -76,6 +76,9 @@ extern char * strpbrk(const char *,const char *);
#ifndef __HAVE_ARCH_STRSEP
extern char * strsep(char **,const char *);
#endif
+#ifndef __HAVE_ARCH_STRTOK_R
+extern char *strtok_r(char *, const char *, char **);
+#endif
#ifndef __HAVE_ARCH_STRSPN
extern __kernel_size_t strspn(const char *,const char *);
#endif
diff --git a/lib/string.c b/lib/string.c
index b19b87a..04461b0 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -493,6 +493,49 @@ char *strsep(char **s, const char *ct)
EXPORT_SYMBOL(strsep);
#endif
+#ifndef __HAVE_ARCH_STRTOK_R
+/**
+ * strtok_r - extract tokens from strings
+ * @s: The string to be searched
+ * @ct: The characters to deliminate the tokens
+ * @saveptr: The pointer to the next token
+ *
+ * It returns the next token found outside of the @ct delimiters.
+ * Multiple occurrences of @ct characters will be considered
+ * a single delimiter. In other words, the returned token will
+ * always have a size greater than 0 (or NULL if no token found).
+ *
+ * A '\0' is placed at the end of the found token, and
+ * @saveptr is updated to point to the location after that.
+ */
+char *strtok_r(char *s, const char *ct, char **saveptr)
+{
+ char *ret;
+ int skip;
+
+ if (!s)
+ return NULL;
+
+ /* Find start of first token */
+ skip = strspn(s, ct);
+ *saveptr = s + skip;
+
+ /* return NULL if we found no token */
+ if (!*saveptr[0])
+ return NULL;
+
+ /*
+ * strsep is different than strtok, where as saveptr will be NULL
+ * if token not found. strtok makes it point to the end of the string.
+ */
+ ret = strsep(saveptr, ct);
+ if (!*saveptr)
+ *saveptr = &ret[strlen(ret)];
+ return ret;
+}
+EXPORT_SYMBOL(strtok_r);
+#endif
+
/**
* sysfs_streq - return true if strings are equal, modulo trailing newline
* @s1: one string
--
1.5.6.5
--
next prev parent reply other threads:[~2009-02-26 19:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-26 18:54 [PATCH v3 0/6] [RFC] copy_strtok_from_user Steven Rostedt
2009-02-26 18:54 ` [PATCH v3 1/6] uaccess: move probe_kernel_* functions to lib/uaccess.c Steven Rostedt
2009-02-26 18:54 ` Steven Rostedt [this message]
2009-02-26 18:54 ` [PATCH v3 3/6] uaccess: add copy_strtok_from_user Steven Rostedt
2009-02-26 18:54 ` [PATCH v3 4/6] tracing: convert event_trace to use copy_strtok_from_user Steven Rostedt
2009-02-26 18:54 ` [PATCH v3 5/6] tracing: convert ftrace_regex_write " Steven Rostedt
2009-02-26 18:54 ` [PATCH v3 6/6] tracing: convert ftrace_graph_write " Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090226185901.113852600@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=srostedt@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox