我需要對寫入我的模塊的數據進行解析,並且使用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