]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/sbr/fdcompare.c
Always check that mktemp()/mktemp2() succeeds before trying to
[nmh] / docs / historical / mh-6.8.5 / sbr / fdcompare.c
1 /* fdcompare.c - are two files identical? */
2 #ifndef lint
3 static char Id[] = "@(#)$Id: fdcompare.c,v 1.4 1993/08/25 18:29:28 jromine Exp $";
4 #endif
5
6 #include "../h/mh.h"
7 #include <stdio.h>
8 #include <sys/types.h> /* for off_t */
9
10 off_t lseek();
11
12
13 fdcompare (fd1, fd2)
14 register int fd1,
15 fd2;
16 {
17 register int i,
18 n1,
19 n2,
20 resp;
21 register char *c1,
22 *c2;
23 char b1[BUFSIZ],
24 b2[BUFSIZ];
25
26 resp = 1;
27 while ((n1 = read (fd1, b1, sizeof b1)) >= 0
28 && (n2 = read (fd2, b2, sizeof b2)) >= 0
29 && n1 == n2) {
30 c1 = b1;
31 c2 = b2;
32 for (i = n1 < sizeof b1 ? n1 : sizeof b1; i--;)
33 if (*c1++ != *c2++) {
34 resp = 0;
35 goto leave;
36 }
37 if (n1 < sizeof b1)
38 goto leave;
39 }
40 resp = 0;
41
42 leave: ;
43 (void) lseek (fd1, (off_t)0, 0);
44 (void) lseek (fd2, (off_t)0, 0);
45 return resp;
46 }