Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4733271
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: LINUX

2010-01-26 14:52:43

  其实看看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!!!注意这个可不能在用户态使用


阅读(2502) | 评论(0) | 转发(0) |
0

上一篇:shell数组

下一篇:Linux内核模块参数权限

给主人留下些什么吧!~~