Files
SCR/SCR3.1/TP2/Ex1/copy.c
2025-09-18 14:06:06 +02:00

36 lines
498 B
C

#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#define BLOCK_SIZE 1
int main(int argc, char *argv[])
{
int fin,
fout;
char buf[BLOCK_SIZE];
assert( argc == 3 );
fin = fopen(argv[1],"r");
assert( fin >= 0 );
fout = fopen(argv[2],O_CREAT|O_WRONLY|O_TRUNC);
assert( fout >= 0 );
while(1){
ssize_t nb_read;
nb_read = fread(fin,buf,BLOCK_SIZE);
if (nb_read <= 0)
break;
fwrite(fout,buf,nb_read);
}
fclose(fin);
fclose(fout);
return 0;
}