我需要对写入我的模块的数据进行解析,并且使用string.h的strtok()函数会很有用。不过,我已经试过我可以在Linux内核模块中使用strtok()吗?
#include <string.h>
和
#include <linux/string.h>
没有成功。这可能吗?或者我将不得不写我自己的strtok功能?
感谢
我需要对写入我的模块的数据进行解析,并且使用string.h的strtok()函数会很有用。不过,我已经试过我可以在Linux内核模块中使用strtok()吗?
#include <string.h>
和
#include <linux/string.h>
没有成功。这可能吗?或者我将不得不写我自己的strtok功能?
感谢
有有效的Linux内核API中没有strtok
。你将不得不写你自己的。请参阅Linux Kernel API中的String Manipulation部分。
顺便说一句,我建议远离strtok
(或任何strtok
样)。它不是可重入的,并且在内核代码中是不安全的(这本质上是多线程的)。
如果您要复制该功能,请考虑复制strtok_r
。
最新的内核库有这一点,这可能就是你所需要的东西:
/**
* 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. ;)
*/
的char * strsep(字符** S,为const char * CT)
将是函数,你正在寻找。
You can look it up in lxr, source/lib/string.c, line 589 (for version/release 4.6)
好的真棒,至少我知道我必须现在写我自己,谢谢! – cheesysam 2010-02-11 18:25:17