Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15340274
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2009-02-04 15:58:50

#include
#include
#include
#include
#include

static int check_wlan_chip(const char *tag, int secs)
{
#define DRIVER_LIVE_FILE    "/proc/wlan_chip"  
    char *line;
    int line_size;
    FILE *proc;
    int delay;

    line_size = strlen(tag) + 1;
    line = malloc(line_size);
    secs *= 10;
    //setvbuf(proc, NULL, _IONBF, 0);
    for (delay = 0; delay < secs; delay++) {

        if ((proc = fopen(DRIVER_LIVE_FILE, "r")) == NULL) {
            fprintf(stderr, "Error : %s : %s\n", DRIVER_LIVE_FILE, strerror(errno));
            free(line);
            return 0;
        }
       
        while ((fgets(line, line_size, proc)) != NULL) {
            if (strncmp(line, tag, line_size) == 0) {
                fclose(proc);
                free(line);
                return 1;
            }
            printf(line);
        }

        fclose(proc);
        //fseek(proc, 0, SEEK_SET);
        //fflush(proc);
        usleep(100*1000);
    }
   
    free(line);
    return 0;
}

int main(void)
{
    return check_wlan_chip("driver=live", 20);
}

阅读(2215) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~