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