1 /*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)special.c 8.1 (Berkeley) 06/06/93"; 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 19 void 20 c_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("%6qd %3o %3o\n", byte, ch1, ch2); 52 } else 53 diffmsg(file1, file2, byte, line); 54 /* NOTREACHED */ 55 if (ch1 == '\n') 56 ++line; 57 } 58 59 eof: 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 } 72