我可以使用的strtok()在Linux内核模块? [英] Can I use strtok() in a Linux Kernel Module?
问题描述
我需要做对写入我的模块的数据的解析,和使用string.h中的的strtok()函数将是有益的。不过,我已经试过
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>
和
#include <linux/string.h>
没有成功。这可能吗?或将我不得不写我自己的strtok功能?
with no success. Is this possible? Or will I have to write my own strtok function?
感谢
推荐答案
有没有 strtok的
有效的Linux内核的API中。你将不得不自己编写。请参见<一个href=\"http://www.cs.bham.ac.uk/~exr/teaching/lectures/systems/08_09/docs/kernelAPI/x1820.html\">String操作 Linux内核API中
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.
顺便说一句,我建议住在 strtok的
离开(或任何 strtok的
样)。这不是折返,并在内核code不安全的(这本身就是多线程)。
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).
如果你要复制功能,可以考虑复制 strtok_r
。
If you're going to duplicate the function, consider duplicating strtok_r
.
这篇关于我可以使用的strtok()在Linux内核模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!