Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use strtok() in a Linux Kernel Module?

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

like image 491
cheesysam Avatar asked Feb 11 '10 18:02

cheesysam


People also ask

How do I see what is using my kernel module?

You can try lsmod | grep <module name> to see all loaded kernel modules that are using a module. You can also try dmesg | grep <module name> to see if the kernel logs have any clues as to which processes may be using a module.

What can you do with kernel modules?

In computing, a loadable kernel module (LKM) is an object file that contains code to extend the running kernel, or so-called base kernel, of an operating system. LKMs are typically used to add support for new hardware (as device drivers) and/or filesystems, or for adding system calls.

Does Linux kernel have main function?

The kernel does not have a main function. main is a concept of the C language. The kernel is written in C and assembly. The entry code of the kernel is written by assembly.


1 Answers

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. ;)
 */
like image 78
Tim Schaeffer Avatar answered Sep 18 '22 00:09

Tim Schaeffer