在指定的文件描述符中查找token,

来源:互联网 发布:酒店智能门锁 网络 编辑:程序博客网 时间:2024/06/06 19:50
int grepdata(char *buf,int fd) {
        off_t n;
        char t[MAXLINE];
        char destbuf[MAXLINE];
        char srcbuf[MAXLINE];
#ifdef DEBUG
//      fprintf(stderr,"t is %s\n",t);
#endif
        trapright(buf," \t\n",srcbuf);
#ifdef DEBUG
        fprintf(stderr,"srcbuf after trapright is %s\n",srcbuf);
#endif
        n = lseek(fd,0,SEEK_SET);
        if (n == -1) {
                return -1;
        }
        while ((n = readline(fd,t,MAXLINE)) !=0) {
                trapright(t," \t\n",destbuf);
                if (strcmp(destbuf,srcbuf) == 0)
                        return 1;
        }
        return 0;

}

token 保存在buf中,找到返回1,未找到返回0,出错返回-1

原创粉丝点击