36 lines
681 B
C
36 lines
681 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#define SZBUF 256
|
|
int main(int argc, char *argv[]){
|
|
int fs, fd, m, n;
|
|
char buf[SZBUF];
|
|
if (argc < 3){
|
|
fprintf(stderr, "Usage : %s <SRC_FILE> <DST_FILE>\n", argv[0]);
|
|
exit(1);
|
|
}
|
|
fs = open(argv[1], O_RDONLY);
|
|
if (fs == -1){
|
|
perror("Opening source file fails");
|
|
exit(2);
|
|
}
|
|
fd = open(argv[2], O_WRONLY|O_TRUNC|O_CREAT, 0600);
|
|
if (fd == -1){
|
|
perror("Opening destination file fails");
|
|
exit(3);
|
|
}
|
|
while (n = read(fs, buf, SZBUF)){
|
|
m = write(fd , buf, n);
|
|
if (n == -1){
|
|
perror("Writing in file fails");
|
|
exit(4);
|
|
}
|
|
}
|
|
close(fd);
|
|
close(fs);
|
|
exit(0);
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|