Example #1
0
int main(int argc, char *argv[]) {

	if (argc != 2) {
		err_sys("fcntl usarge:<descripter>\n");
	}
	int fd=atoi(argv[1]);
	getfl(fd);
	setfl(fd,O_NONBLOCK);
	getfl(fd);
	exit(0);
}
Example #2
0
File: flags.c Project: raoulb/aldoc
/* Returns the numerical value of a flag, or -1 if not there */
int getFlag(int ac, char **ag, char flag)
{
	int i, val;
	for (i = 1; i < ac; i++)
	    if ((ag[i][0] == FLAG_SIGNAL)
		 && ((val = getfl(ag[i], flag))) >= 0)
			return val;
	return(-1);
}
Example #3
0
int main()
{
    long count=0;  //文件中每行数据用|+|分割的字段数
    long l=0;     //文件行数
    long ret=0;
    char *bgn;
    char *end;
    FILE *fp=NULL;
    FILE *print_out=NULL;
    char tmp_str[512];
    fp=fopen("/Users/zhanglei/Study/job/c/file_deal/file.txt","r");
    print_out=fopen("/Users/zhanglei/Study/job/c/file_deal/file_out.txt","a+");
    if(fp==NULL || print_out==NULL)
    {
        return 1;
    }
    fprintf(print_out,"--------------------------------------------\n");
    //循环处理每行数据
    while(1)
    {
        memset(src_buf,0x00,sizeof(src_buf));
        p=0;
		count=0;
		//fgets读取文件的时候,若bufsize大于该行的字符总数加2('\n','\0'),文件仅仅只是这一行读取完,随后指向文件的指针会自动偏移至下一行
        if(fgets(src_buf,sizeof(src_buf),fp)==NULL)
        {
            if(0==l)
			{
				fprintf(print_out,"文件为空!");
				return 1;
			}
			else
			{
                fprintf(print_out,"文件读取完毕!\n");
                break;
	    	}
        }
		l++;
    //src_buf存储每行数据
		rtrim(src_buf);
        fprintf(print_out,"src_buf:[%s]\n",src_buf);
        end=strstr(src_buf,"|-|");
        while(1)
        {
            bgn = (char *)&src_buf[p];
            char *prt=strstr(bgn,"|+|");
            if( prt != NULL)
            {
                p+=prt-bgn+3;
                count++;
            }
            else
            {
                p+=end-bgn;
                count++;
                break;
            }
        }
        fprintf(print_out,"p=[%d],src_buf[p]=[%c],count=[%d]\n",p,src_buf[p],count);
		p=0;
		for(;count>0;count--)
		{
            memset(tmp_str,0x00,sizeof(tmp_str));
            //获取每个字段
	    	ret=getfl(tmp_str);
	    	if(0!=ret)
			fprintf(print_out,"getfl调用失败!");
	    	fprintf(print_out,"tmp_str:%s\n",tmp_str);
		}
    }
    fprintf(print_out,"文件行数:[%d]\n",l);
    fprintf(print_out,"--------------------------------------------\n");
    fclose(fp);
    fclose(print_out);
    return 0;
}