Fix order of 2nd and 3rd arguments to fread so the count of the
[unix-history] / usr / src / usr.bin / diff / diff / diffreg.c
index f727773..255305e 100644 (file)
@@ -1,4 +1,4 @@
-static char sccsid[] = "@(#)diffreg.c 4.4 %G%";
+static char sccsid[] = "@(#)diffreg.c 4.6 %G%";
 
 #include "diff.h"
 /*
 
 #include "diff.h"
 /*
@@ -137,13 +137,14 @@ diffreg()
        if (stb1.st_size != stb2.st_size)
                goto notsame;
        for (;;) {
        if (stb1.st_size != stb2.st_size)
                goto notsame;
        for (;;) {
-               i = fread(buf1, BUFSIZ, 1, f1);
-               j = fread(buf2, BUFSIZ, 1, f2);
+               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);
                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++)
                        goto same;
                }
                for (j = 0; j < i; j++)
@@ -151,6 +152,10 @@ diffreg()
                                goto notsame;
        }
 notsame:
                                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);
        if (!asciifile(f1) || !asciifile(f2)) {
                printf("Binary files %s and %s differ\n", file1, file2);
                fclose(f1);
@@ -773,7 +778,7 @@ asciifile(f)
        register char *cp;
 
        fseek(f, (long)0, 0);
        register char *cp;
 
        fseek(f, (long)0, 0);
-       cnt = fread(buf, BUFSIZ, 1, f);
+       cnt = fread(buf, 1, BUFSIZ, f);
        if (cnt >= sizeof (struct exec)) {
                struct exec hdr;
                hdr = *(struct exec *)buf;
        if (cnt >= sizeof (struct exec)) {
                struct exec hdr;
                hdr = *(struct exec *)buf;