Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/diff/diffreg.c
| Show First 20 Lines • Show All 400 Lines • ▼ Show 20 Lines | diffreg_stone(char *file1, char *file2, int flags, int capsicum) | ||||
| switch (files_differ(f1, f2, flags)) { | switch (files_differ(f1, f2, flags)) { | ||||
| case 0: | case 0: | ||||
| goto closem; | goto closem; | ||||
| case 1: | case 1: | ||||
| break; | break; | ||||
| default: | default: | ||||
| /* error */ | /* error */ | ||||
| if (ferror(f1)) | |||||
| warn("%s", file1); | |||||
| if (ferror(f2)) | |||||
| warn("%s", file2); | |||||
| rval = D_ERROR; | rval = D_ERROR; | ||||
| status |= 2; | status |= 2; | ||||
| goto closem; | goto closem; | ||||
| } | } | ||||
| if (diff_format == D_BRIEF && ignore_pats == NULL && | if (diff_format == D_BRIEF && ignore_pats == NULL && | ||||
| (flags & (D_FOLDBLANKS|D_IGNOREBLANKS|D_IGNORECASE| | (flags & (D_FOLDBLANKS|D_IGNOREBLANKS|D_IGNORECASE| | ||||
| D_SKIPBLANKLINES|D_STRIPCR)) == 0) | D_SKIPBLANKLINES|D_STRIPCR)) == 0) | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | files_differ(FILE *f1, FILE *f2, int flags) | ||||
| if ((flags & (D_EMPTY1|D_EMPTY2)) || stb1.st_size != stb2.st_size || | if ((flags & (D_EMPTY1|D_EMPTY2)) || stb1.st_size != stb2.st_size || | ||||
| (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT)) | (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT)) | ||||
| return (1); | return (1); | ||||
| if (stb1.st_dev == stb2.st_dev && stb1.st_ino == stb2.st_ino) | if (stb1.st_dev == stb2.st_dev && stb1.st_ino == stb2.st_ino) | ||||
| return (0); | return (0); | ||||
| for (;;) { | for (;;) { | ||||
| i = fread(buf1, 1, sizeof(buf1), f1); | if ((i = fread(buf1, 1, sizeof(buf1), f1)) == 0 && ferror(f1)) | ||||
| j = fread(buf2, 1, sizeof(buf2), f2); | return (-1); | ||||
| if ((!i && ferror(f1)) || (!j && ferror(f2))) | if ((j = fread(buf2, 1, sizeof(buf2), f2)) == 0 && ferror(f2)) | ||||
| return (-1); | return (-1); | ||||
olce: Putting the assignments in the `if` makes things less readable, especially given that `i` and… | |||||
| if (i != j) | if (i != j) | ||||
| return (1); | return (1); | ||||
| if (i == 0) | if (i == 0) | ||||
| return (0); | return (0); | ||||
| if (memcmp(buf1, buf2, i) != 0) | if (memcmp(buf1, buf2, i) != 0) | ||||
| return (1); | return (1); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,236 Lines • Show Last 20 Lines | |||||
Putting the assignments in the if makes things less readable, especially given that i and j are not used in the test nor if blocks.
You might want to rename i and j for better clarity.