C程序设计语言题目:练习8-1


用read、write、open close 系统调用来替代标准库中的功能等价函数,重写cat程序,经过实验比较两个版本的速度。函数

#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>

int main(int argc ,char **argv)
{
	char buf[32];
	int fd,ret;
	fd = open(argv[1],O_RDONLY,0644);
	while(1){
	 bzero(buf,32);
	ret = read(fd,buf,32);
	 if(ret == 0)
	  { break;}
	else{
	write(1,buf,32);
	}
	}
	close(fd); 
	return 0;
	
}