我可以在 Linux 内核模块中使用 strtok() 吗? [英] Can I use strtok() in a Linux Kernel Module?

查看:35
本文介绍了我可以在 Linux 内核模块中使用 strtok() 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对写入我的模块的数据进行解析,使用 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?

谢谢

推荐答案

在有效的 Linux 内核 API 中没有 strtok.你将不得不自己写.请参阅字符串操作 在 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 的东西).它不是可重入的,并且在内核代码中是不安全的(本质上是多线程的).

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.

这篇关于我可以在 Linux 内核模块中使用 strtok() 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆