]> diplodocus.org Git - nmh/blob - sbr/fdcompare.c
Just reworded the bit about '%s' being safe not to quote (it's only safe not to
[nmh] / sbr / fdcompare.c
1
2 /*
3 * fdcompare.c -- are two files identical?
4 *
5 * $Id$
6 */
7
8 #include <h/mh.h>
9
10
11 int
12 fdcompare (int fd1, int fd2)
13 {
14 register int i, n1, n2, resp;
15 register 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 < sizeof(b1) ? n1 : sizeof(b1); i--;)
25 if (*c1++ != *c2++) {
26 resp = 0;
27 goto leave;
28 }
29 if (n1 < sizeof(b1))
30 goto leave;
31 }
32 resp = 0;
33
34 leave: ;
35 lseek (fd1, (off_t) 0, SEEK_SET);
36 lseek (fd2, (off_t) 0, SEEK_SET);
37 return resp;
38 }