views:

115

answers:

2

I need to do a parse on the data written to my module, and the use of the strtok() function of string.h would be useful. However I've tried

#include <string.h>

and

#include <linux/string.h>

with no success. Is this possible? Or will I have to write my own strtok function?

Thanks

+5  A: 

There is no strtok in the valid Linux Kernel API. You will have to write your own. See the section String Manipulation in the Linux Kernel API.

BTW, I would suggest staying away from strtok (or anything strtok-like). It's not reentrant and is unsafe in kernel code (which is inherently multithreaded).

If you're going to duplicate the function, consider duplicating strtok_r.

0xfe
Ok awesome, at least I know for sure I have to write my own now, Thanks!
cheesysam
+5  A: 

The latest kernel library has this, which may do what you need:

/**
 * strsep - Split a string into tokens
 * @s: The string to be searched
 * @ct: The characters to search for
 *
 * strsep() updates @s to point after the token, ready for the next call.
 *
 * It returns empty tokens, too, behaving exactly like the libc function
 * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
 * Same semantics, slimmer shape. ;)
 */
Tim Schaeffer