#include #include #include #include #define szbuf 256 int main(int argc, char const *argv[]) { char buf[szbuf]; int f1,f2,n,m; if(argc<3) { fprintf(stderr, "Usage : %s ",argv[1]); exit(1); } f1 = open(argv[1],O_RDONLY); if(f1 == -1) { perror("Opening source file fails"); exit(2); } f2 = open(argv[2],O_WRONLY|O_TRUNC|O_CREAT,0600); if(f2 == -1) { perror("Opening destination file fails"); exit(3); } while(n = read(f1,buf,szbuf)) { m = write(f2,buf,n); if(m == -1) { perror("Writing in file fails"); exit(4); } } close(f1); close(f2); exit(0); }