41 lines
652 B
C
41 lines
652 B
C
|
#include<stdio.h>
|
||
|
#include<fcntl.h>
|
||
|
#include<unistd.h>
|
||
|
#include<stdlib.h>
|
||
|
|
||
|
#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 <SRC.FILE><TRUC.FILE>",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);
|
||
|
}
|