#include<unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include<stdio.h> #include<errno.h> int main(int argc,char **argv) { int fd_from, fd_to, byte_read, byte_write; char buff[1024]; if(argc!=3) fprintf(stderr,"usage:%s fd_from fd_to",argv[0]); fd_from=open(argv[1],O_RDONLY ); if(fd_from==-1) fprintf(stderr,"fd_from open:%d",strerror(errno)); fd_to=open(argv[2],O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR); if(fd_to==-1) fprintf(stderr,"fd_to open:%d",strerror(errno)); byte_read=read(fd_from,buff,1024); byte_write=write(fd_to,buff,1024); if(byte_read!=byte_write) printf("the copy is uncomplete!!!"); close(fd_from); close(fd_to); }