- 论坛徽章:
- 0
|
其实看看textsearch.c你就清楚了....
#include linux/module.h>
#include linux/kernel.h>
#include linux/init.h>
#include linux/types.h>
#include linux/string.h>
#include linux/init.h>
#include linux/rcupdate.h>
#include linux/err.h>
#include linux/textsearch.h>
static int o_search()
{
int pos;
long err;
struct ts_config *conf;
struct ts_state state;
const char *pattern = "chicken";
const char *example = "We dance the funky chicken";
conf = textsearch_prepare("kmp", pattern, strlen(pattern),GFP_KERNEL, TS_AUTOLOAD);
if (IS_ERR(conf)) {
err = PTR_ERR(conf);
goto errout;
}
pos = textsearch_find_continuous(conf, &state, example, strlen(example));
if (pos != UINT_MAX)
printk("Oh my god, dancing chickens at %d\n", pos);
textsearch_destroy(conf);
errout:
ERR_PTR(err);
return 0;
}
static int __init search_init(void)
{
printk("%s\n", "search insmod");
o_search();
return 0;
}
static void __exit search_cleanup(void)
{
printk("%s\n", "search rmmod");
}
module_init(search_init);
module_exit(search_cleanup);
如果是bm的话
conf = textsearch_prepare("kmp", pattern, strlen(pattern),GFP_KERNEL, TS_AUTOLOAD);
就可以了
以后内核查找字符串就easy了!!!
原来直接就有api!!!注意这个可不能在用户态使用
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/76292/showart_2161040.html |
|