date and time created 91/10/27 14:14:57 by bostic
[unix-history] / usr / src / usr.bin / cmp / special.c
CommitLineData
40e69ab4
KB
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#ifndef lint
9static char sccsid[] = "@(#)special.c 5.1 (Berkeley) %G%";
10#endif /* not lint */
11
12#include <sys/types.h>
13#include <errno.h>
14#include <stdlib.h>
15#include <stdio.h>
16#include <string.h>
17#include "extern.h"
18
19void
20c_special(fd1, file1, skip1, fd2, file2, skip2)
21 int fd1, fd2;
22 char *file1, *file2;
23 register off_t skip1, skip2;
24{
25 register int ch1, ch2;
26 register off_t byte, line;
27 FILE *fp1, *fp2;
28 int dfound;
29
30 if ((fp1 = fdopen(fd1, "r")) == NULL)
31 err("%s: %s", file1, strerror(errno));
32 if ((fp2 = fdopen(fd2, "r")) == NULL)
33 err("%s: %s", file1, strerror(errno));
34
35 while (skip1--)
36 if (getc(fp1) == EOF)
37 goto eof;
38 while (skip2--)
39 if (getc(fp2) == EOF)
40 goto eof;
41
42 dfound = 0;
43 for (byte = line = 1;; ++byte) {
44 ch1 = getc(fp1);
45 ch2 = getc(fp2);
46 if (ch1 == EOF || ch2 == EOF)
47 break;
48 if (ch1 != ch2)
49 if (lflag) {
50 dfound = 1;
51 (void)printf("%6ld %3o %3o\n", byte, ch1, ch2);
52 } else
53 diffmsg(file1, file2, byte, line);
54 /* NOTREACHED */
55 if (ch1 == '\n')
56 ++line;
57 }
58
59eof: if (ferror(fp1))
60 err("%s: %s", file1, strerror(errno));
61 if (ferror(fp2))
62 err("%s: %s", file2, strerror(errno));
63 if (feof(fp1)) {
64 if (!feof(fp2))
65 eofmsg(file1);
66 } else
67 if (feof(fp2))
68 eofmsg(file2);
69 if (dfound)
70 exit(1);
71}