2012-07-07 08:08:28 +04:00
|
|
|
/*
|
|
|
|
* verify-write
|
|
|
|
*
|
|
|
|
* A dangerous tool to write to a file and verified it worked.
|
|
|
|
*/
|
2012-05-01 04:01:55 +04:00
|
|
|
#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 };
|
2012-10-08 11:17:50 +04:00
|
|
|
execvp(args[0], args);
|
2012-05-01 04:01:55 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|