[英]Can I use strtok() in a Linux Kernel Module?
我需要对写入模块的数据进行解析,并且使用string.h的strtok()函数会很有用。 但是我试过了
#include <string.h>
和
#include <linux/string.h>
没有成功。 这可能吗? 或者我是否必须编写自己的strtok函数?
谢谢
最新的内核库有这个,它可以做你需要的:
/**
* 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. ;)
*/
有效的Linux内核API中没有strtok
。 你必须自己写。 请参阅Linux Kernel API中的String Manipulation部分。
顺便说一句,我建议远离strtok
(或任何类似strtok
)。 它不是可重入的,并且在内核代码(本质上是多线程的)中是不安全的。
如果您要复制该函数,请考虑复制strtok_r
。
char * strsep(char ** s,const char * ct)
将是你正在寻找的功能。
你可以在lxr,source / lib / string.c,第589行查找(对于版本/版本4.6)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.