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