40 lines
838 B
C
40 lines
838 B
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
#define CHUNK_SIZE 1024
|
|
|
|
int main(int argc, char * argv[]) {
|
|
if (argc < 3) {
|
|
printf("Expected two arguments, the file to read, and the filename to write out to.\nTry again, maybe?\n");
|
|
return -1;
|
|
}
|
|
FILE * input = fopen(argv[1], "r");
|
|
FILE * output = fopen(argv[2], "w");
|
|
size_t length;
|
|
|
|
fseek(input, 0, SEEK_END);
|
|
length = ftell(input);
|
|
fseek(input, 0, SEEK_SET);
|
|
|
|
char buf[CHUNK_SIZE];
|
|
while (length > CHUNK_SIZE) {
|
|
fread( buf, 1, CHUNK_SIZE, input);
|
|
fwrite(buf, 1, CHUNK_SIZE, output);
|
|
fflush(output);
|
|
length -= CHUNK_SIZE;
|
|
}
|
|
if (length > 0) {
|
|
fread( buf, 1, length, input);
|
|
fwrite(buf, 1, length, output);
|
|
fflush(output);
|
|
}
|
|
|
|
fclose(output);
|
|
fclose(input);
|
|
|
|
char * args[] = {"/bin/compare", argv[1], argv[2], NULL };
|
|
execve(args[0], args, NULL);
|
|
|
|
return 0;
|
|
}
|