+ if ((f1 = fopen(file1, "r")) == NULL) {
+ fprintf(stderr, "diff: ");
+ perror(file1);
+ fclose(f1);
+ done();
+ }
+ if ((f2 = fopen(file2, "r")) == NULL) {
+ fprintf(stderr, "diff: ");
+ perror(file2);
+ fclose(f1);
+ fclose(f2);
+ done();
+ }
+ if (stb1.st_size != stb2.st_size)
+ goto notsame;
+ for (;;) {
+ i = fread(buf1, 1, BUFSIZ, f1);
+ j = fread(buf2, 1, BUFSIZ, f2);
+ if (i < 0 || j < 0 || i != j)
+ goto notsame;
+ if (i == 0 && j == 0) {
+ fclose(f1);
+ fclose(f2);
+ status = 0; /* files don't differ */
+ goto same;
+ }
+ for (j = 0; j < i; j++)
+ if (buf1[j] != buf2[j])
+ goto notsame;
+ }
+notsame:
+ /*
+ * Files certainly differ at this point; set status accordingly
+ */
+ status = 1;
+ if (!asciifile(f1) || !asciifile(f2)) {
+ printf("Binary files %s and %s differ\n", file1, file2);
+ fclose(f1);
+ fclose(f2);
+ done();
+ }
+ prepare(0, f1);
+ prepare(1, f2);
+ fclose(f1);
+ fclose(f2);