From: Steven Rostedt 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 --- 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 -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/