显示文件内容的脚本


显示文件内容的脚本
 
C代码  www.2cto.com  
#include <stdio.h>  
#include <fcntl.h>  
#include <malloc.h>  
#include <string.h>  
#include <unistd.h>  
#include <stdlib.h>  
int main(int argc,char *argv[])  
{  
    int fd,i=1,a,c,t;  
    int tsize;  
    char *buf;  
    buf=malloc(sizeof(char)*256);  
    if(argv[2]==NULL) c=1;  
        else  c=atoi(argv[2]);  
    if(c<=0) c=1;  
    for(a=1;a<=c;a++)  
    {  
        fd=open(argv[1],O_RDONLY);  
        if(fd<0)  
        {     
            printf("Not find file!\n");  
        }  
        i=1;  
        t=1;  
            while(i>0)  
        {  
            memset(buf,0,256);  
            i=read(fd,buf,256);  
            if((t%2)==0) usleep(20000);  
            if((t%5)==0) usleep(800000);  
                        if((t%3)==0) usleep(500000);  
                        if((t%10)==0) usleep(1000000);  
                        usleep(500000);      
            printf("%s",buf);  
            t++;  
        }  
        printf("**********************************************************************\n");  
        sleep(2);  
        close(fd);  
    }  
    return 0;  
}  
 

相关内容

    暂无相关文章