r305_dm/TP2/Exo1/copy.c

36 lines
484 B
C
Raw Normal View History

2023-09-14 16:01:56 +02:00
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#define BLOCK_SIZE 1
int main(int argc, char *argv[])
{
int fin,
fout;
char buf[BLOCK_SIZE];
assert( argc == 3 );
fin = open(argv[1],O_RDONLY);
assert( fin >= 0 );
fout = open(argv[2],O_CREAT|O_WRONLY|O_TRUNC,0600);
assert( fout >= 0 );
while(1){
ssize_t nb_read;
nb_read = read(fin,buf,BLOCK_SIZE);
if (nb_read <= 0)
break;
write(fout,buf,nb_read);
}
close(fin);
close(fout);
return 0;
}