#include#include #include #include #include #include #define DATA_SIZE 30 int my_copy(int argc,char **argv); int main(int argc,char **argv) { my_copy(argc,argv); return 0; } // ./my_copy dest.txt src.txt int my_copy(int argc,char **argv) { int fd_src,fd_dest; char buf[DATA_SIZE]; int count = 0; if(argc != 3 ) { perror("input error"); return -1; } fd_src = open(argv[2],O_RDONLY); if(fd_src == -1){ perror("open failed"); return -1; } fd_dest = open(argv[1],O_WRONLY | O_CREAT | O_EXCL,0700); if(fd_dest == -1){ close(fd_src); perror("open failed"); return -1; } while(1){ count = read(fd_src,buf,DATA_SIZE); if(count == -1 ) { perror("read failed"); return -1; } if(count == 0) break; write(fd_dest,buf,count); } close(fd_src); close(fd_dest); }



