#define LARGEFILE_SOURCE #define LARGEFILE64_SOURCE #define FILE_OFFSET_BITS 64 #include #include #define BUFFER_SIZE 0x100000 int main(int argc, char *argv[]) { if(argc < 3) { fprintf(stderr, "Need 2 files to compare.\n"); exit(1); } FILE *file1 = fopen64(argv[1], "r"); if(!file1) { perror("Opening file 1"); exit(1); } FILE *file2 = fopen64(argv[2], "r"); if(!file2) { perror("Opening file 2"); exit(1); } unsigned char *buffer1 = calloc(1, BUFFER_SIZE); unsigned char *buffer2 = calloc(1, BUFFER_SIZE); int i; int64_t current_position = 0; while(!feof(file1) && !feof(file2)) { printf("Testing byte 0x%x\r", current_position); fflush(stdout); int file1_bytes = fread(buffer1, 1, BUFFER_SIZE, file1); int file2_bytes = fread(buffer2, 1, BUFFER_SIZE, file2); for(i = 0; i < file1_bytes && i < file2_bytes; i++) { if(buffer1[i] != buffer2[i]) { printf("Got a difference at byte 0x%x\n", current_position + i); // exit(0); } } if(file1_bytes != file2_bytes) { printf("Files are different lengths.\n"); exit(0); } current_position += file1_bytes; } }