]> diplodocus.org Git - nmh/blob - sbr/fdcompare.c
sendsbr.c: Move interface to own file.
[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 #include "fdcompare.h"
10
11
12 int
13 fdcompare (int fd1, int fd2)
14 {
15 int i, n1, n2;
16 char *c1, *c2;
17 char b1[BUFSIZ], b2[BUFSIZ];
18
19 bool resp = true;
20 while ((n1 = read (fd1, b1, sizeof(b1))) >= 0
21 && (n2 = read (fd2, b2, sizeof(b2))) >= 0
22 && n1 == n2) {
23 c1 = b1;
24 c2 = b2;
25 for (i = n1 < (int) sizeof(b1) ? n1 : (int) sizeof(b1); i--;)
26 if (*c1++ != *c2++) {
27 resp = false;
28 goto leave;
29 }
30 if (n1 < (int) sizeof(b1))
31 goto leave;
32 }
33 resp = false;
34
35 leave: ;
36 lseek(fd1, 0, SEEK_SET);
37 lseek(fd2, 0, SEEK_SET);
38 return resp;
39 }