#include <stdio.h>
#include <string.h>
#include <errno.h>
#define BUF_SIZE 32
int main(int argc, char *argv[])
{
if (argc != 3)
{
printf("Uage: ./copy dest src");
return -1;
}
char *src = argv[1];
char *dest = argv[2];
FILE* file1 = fopen(dest, "r");
FILE* file2 = fopen(src, "w+");
char file1_buf[BUF_SIZE];
while(1)
{
int ret = fread(file1_buf, sizeof(char), BUF_SIZE, file1);
ret = fwrite(file1_buf, 1, ret, file2);
if (ret < BUF_SIZE)
{
printf("write %s %s\n" , dest, strerror(errno));
return 0;
}
}
fclose(file1);
fclose(file2);
return 0;
}