]> diplodocus.org Git - nmh/blob - sbr/fdcompare.c
mhbuildsbr.c: Flip logic, moving goto to then-block; no need for else.
[nmh] / sbr / fdcompare.c
1 /* fdcompare.c -- are two files identical?
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9
10
11 int
12 fdcompare (int fd1, int fd2)
13 {
14 int i, n1, n2, resp;
15 char *c1, *c2;
16 char b1[BUFSIZ], b2[BUFSIZ];
17
18 resp = 1;
19 while ((n1 = read (fd1, b1, sizeof(b1))) >= 0
20 && (n2 = read (fd2, b2, sizeof(b2))) >= 0
21 && n1 == n2) {
22 c1 = b1;
23 c2 = b2;
24 for (i = n1 < (int) sizeof(b1) ? n1 : (int) sizeof(b1); i--;)
25 if (*c1++ != *c2++) {
26 resp = 0;
27 goto leave;
28 }
29 if (n1 < (int) sizeof(b1))
30 goto leave;
31 }
32 resp = 0;
33
34 leave: ;
35 lseek(fd1, 0, SEEK_SET);
36 lseek(fd2, 0, SEEK_SET);
37 return resp;
38 }