diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-10-18 08:53:40 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-10-18 08:53:40 +0000 |
commit | d6583bb2a13f329cf0332ef2570eb8bb8fc0e39c (patch) | |
tree | ece253b876159b39c620e62b6c9b1174642e070e /usr.bin/cmp |
initial import of NetBSD tree
Diffstat (limited to 'usr.bin/cmp')
-rw-r--r-- | usr.bin/cmp/Makefile | 7 | ||||
-rw-r--r-- | usr.bin/cmp/cmp.1 | 109 | ||||
-rw-r--r-- | usr.bin/cmp/cmp.c | 152 | ||||
-rw-r--r-- | usr.bin/cmp/extern.h | 47 | ||||
-rw-r--r-- | usr.bin/cmp/misc.c | 70 | ||||
-rw-r--r-- | usr.bin/cmp/regular.c | 104 | ||||
-rw-r--r-- | usr.bin/cmp/special.c | 105 |
7 files changed, 594 insertions, 0 deletions
diff --git a/usr.bin/cmp/Makefile b/usr.bin/cmp/Makefile new file mode 100644 index 00000000000..32bdfb03727 --- /dev/null +++ b/usr.bin/cmp/Makefile @@ -0,0 +1,7 @@ +# @(#)Makefile 8.1 (Berkeley) 6/6/93 +# $NetBSD: Makefile,v 1.3 1995/09/08 03:22:54 tls Exp $ + +PROG= cmp +SRCS= cmp.c misc.c regular.c special.c + +.include <bsd.prog.mk> diff --git a/usr.bin/cmp/cmp.1 b/usr.bin/cmp/cmp.1 new file mode 100644 index 00000000000..4d3fd05ac40 --- /dev/null +++ b/usr.bin/cmp/cmp.1 @@ -0,0 +1,109 @@ +.\" $NetBSD: cmp.1,v 1.4 1995/09/08 03:22:55 tls Exp $ +.\" +.\" Copyright (c) 1987, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)cmp.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt CMP 1 +.Os +.Sh NAME +.Nm cmp +.Nd compare two files +.Sh SYNOPSIS +.Nm cmp +.Op Fl l | Fl s +.Ar file1 file2 +.Op Ar skip1 Op Ar skip2 +.Sh DESCRIPTION +The cmp utility compares two files of any type and writes the results +to the standard output. +By default, +.Nm +is silent if the files are the same; if they differ, the byte +and line number at which the first difference occurred is reported. +.Pp +Bytes and lines are numbered beginning with one. +.Pp +The following options are available: +.Bl -tag -width flag +.It Fl l +Print the byte number (decimal) and the differing +byte values (octal) for each difference. +.It Fl s +Print nothing for differing files; return exit +status only. +.El +.Pp +The optional arguments +.Ar skip1 +and +.Ar skip2 +are the byte offsets from the beginning of +.Ar file1 +and +.Ar file2 , +respectively, where the comparison will begin. +The offset is decimal by default, but may be expressed as an hexadecimal +or octal value by preceding it with a leading ``0x'' or ``0''. +.Pp +The +.Nm cmp +utility exits with one of the following values: +.Bl -tag -width 4n +.It 0 +The files are identical. +.It 1 +The files are different; this includes the case +where one file is identical to the first part of +the other. +In the latter case, if the +.Fl s +option has not been specified, +.Nm cmp +writes to standard output that EOF was reached in the shorter +file (before any differences were found). +.It >1 +An error occurred. +.El +.Sh SEE ALSO +.Xr diff 1 , +.Xr diff3 1 +.Sh STANDARDS +The +.Nm cmp +utility is expected to be +.St -p1003.2 +compatible. diff --git a/usr.bin/cmp/cmp.c b/usr.bin/cmp/cmp.c new file mode 100644 index 00000000000..51d17f8186c --- /dev/null +++ b/usr.bin/cmp/cmp.c @@ -0,0 +1,152 @@ +/* $NetBSD: cmp.c,v 1.7 1995/09/08 03:22:56 tls Exp $ */ + +/* + * Copyright (c) 1987, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright (c) 1987, 1990, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmp.c 8.3 (Berkeley) 4/2/94"; +#else +static char rcsid[] = "$NetBSD: cmp.c,v 1.7 1995/09/08 03:22:56 tls Exp $"; +#endif +#endif /* not lint */ + +#include <sys/types.h> +#include <sys/stat.h> + +#include <err.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <locale.h> + +#include "extern.h" + +int lflag, sflag; + +static void usage __P((void)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + struct stat sb1, sb2; + off_t skip1, skip2; + int ch, fd1, fd2, special; + char *file1, *file2; + + setlocale(LC_ALL, ""); + + while ((ch = getopt(argc, argv, "ls")) != EOF) + switch (ch) { + case 'l': /* print all differences */ + lflag = 1; + break; + case 's': /* silent run */ + sflag = 1; + break; + case '?': + default: + usage(); + } +endargs: + argv += optind; + argc -= optind; + + if (lflag && sflag) + errx(ERR_EXIT, "only one of -l and -s may be specified"); + + if (argc < 2 || argc > 4) + usage(); + + /* Backward compatibility -- handle "-" meaning stdin. */ + special = 0; + if (strcmp(file1 = argv[0], "-") == 0) { + special = 1; + fd1 = 0; + file1 = "stdin"; + } + else if ((fd1 = open(file1, O_RDONLY, 0)) < 0) + err(ERR_EXIT, "%s", file1); + if (strcmp(file2 = argv[1], "-") == 0) { + if (special) + errx(ERR_EXIT, + "standard input may only be specified once"); + special = 1; + fd2 = 0; + file2 = "stdin"; + } + else if ((fd2 = open(file2, O_RDONLY, 0)) < 0) + err(ERR_EXIT, "%s", file2); + + skip1 = argc > 2 ? strtoq(argv[2], NULL, 10) : 0; + skip2 = argc == 4 ? strtoq(argv[3], NULL, 10) : 0; + + if (!special) { + if (fstat(fd1, &sb1)) + err(ERR_EXIT, "%s", file1); + if (!S_ISREG(sb1.st_mode)) + special = 1; + else { + if (fstat(fd2, &sb2)) + err(ERR_EXIT, "%s", file2); + if (!S_ISREG(sb2.st_mode)) + special = 1; + } + } + + if (special) + c_special(fd1, file1, skip1, fd2, file2, skip2); + else + c_regular(fd1, file1, skip1, sb1.st_size, + fd2, file2, skip2, sb2.st_size); + exit(0); +} + +static void +usage() +{ + + (void)fprintf(stderr, + "usage: cmp [-l | s] file1 file2 [skip1 [skip2]]\n"); + exit(ERR_EXIT); +} diff --git a/usr.bin/cmp/extern.h b/usr.bin/cmp/extern.h new file mode 100644 index 00000000000..ca02c60020d --- /dev/null +++ b/usr.bin/cmp/extern.h @@ -0,0 +1,47 @@ +/* $NetBSD: extern.h,v 1.2 1995/09/08 03:22:57 tls Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)extern.h 8.3 (Berkeley) 4/2/94 + */ + +#define OK_EXIT 0 +#define DIFF_EXIT 1 +#define ERR_EXIT 2 /* error exit code */ + +void c_regular __P((int, char *, off_t, off_t, int, char *, off_t, off_t)); +void c_special __P((int, char *, off_t, int, char *, off_t)); +void diffmsg __P((char *, char *, off_t, off_t)); +void eofmsg __P((char *)); + +extern int lflag, sflag; diff --git a/usr.bin/cmp/misc.c b/usr.bin/cmp/misc.c new file mode 100644 index 00000000000..a6c83495c7e --- /dev/null +++ b/usr.bin/cmp/misc.c @@ -0,0 +1,70 @@ +/* $NetBSD: misc.c,v 1.2 1995/09/08 03:22:58 tls Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94"; +#else +static char rcsid[] = "$NetBSD: misc.c,v 1.2 1995/09/08 03:22:58 tls Exp $"; +#endif +#endif /* not lint */ + +#include <sys/types.h> + +#include <err.h> +#include <stdio.h> +#include <stdlib.h> + +#include "extern.h" + +void +eofmsg(file) + char *file; +{ + if (!sflag) + warnx("EOF on %s", file); + exit(DIFF_EXIT); +} + +void +diffmsg(file1, file2, byte, line) + char *file1, *file2; + off_t byte, line; +{ + if (!sflag) + (void)printf("%s %s differ: char %qd, line %qd\n", + file1, file2, byte, line); + exit(DIFF_EXIT); +} diff --git a/usr.bin/cmp/regular.c b/usr.bin/cmp/regular.c new file mode 100644 index 00000000000..d1e8ceae8b4 --- /dev/null +++ b/usr.bin/cmp/regular.c @@ -0,0 +1,104 @@ +/* $NetBSD: regular.c,v 1.2 1995/09/08 03:22:59 tls Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)regular.c 8.3 (Berkeley) 4/2/94"; +#else +static char rcsid[] = "$NetBSD: regular.c,v 1.2 1995/09/08 03:22:59 tls Exp $"; +#endif +#endif /* not lint */ + +#include <sys/param.h> +#include <sys/mman.h> +#include <sys/stat.h> + +#include <err.h> +#include <limits.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "extern.h" + +void +c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2) + int fd1, fd2; + char *file1, *file2; + off_t skip1, len1, skip2, len2; +{ + u_char ch, *p1, *p2; + off_t byte, length, line; + int dfound; + + if (sflag && len1 != len2) + exit(1); + + if (skip1 > len1) + eofmsg(file1); + len1 -= skip1; + if (skip2 > len2) + eofmsg(file2); + len2 -= skip2; + + length = MIN(len1, len2); + if (length > SIZE_T_MAX) + return (c_special(fd1, file1, skip1, fd2, file2, skip2)); + + if ((p1 = (u_char *)mmap(NULL, + (size_t)length, PROT_READ, 0, fd1, skip1)) == (u_char *)-1) + err(ERR_EXIT, "%s", file1); + if ((p2 = (u_char *)mmap(NULL, + (size_t)length, PROT_READ, 0, fd2, skip2)) == (u_char *)-1) + err(ERR_EXIT, "%s", file2); + + dfound = 0; + for (byte = line = 1; length--; ++p1, ++p2, ++byte) { + if ((ch = *p1) != *p2) + if (lflag) { + dfound = 1; + (void)printf("%6qd %3o %3o\n", byte, ch, *p2); + } else + diffmsg(file1, file2, byte, line); + /* NOTREACHED */ + if (ch == '\n') + ++line; + } + + if (len1 != len2) + eofmsg (len1 > len2 ? file2 : file1); + if (dfound) + exit(DIFF_EXIT); +} diff --git a/usr.bin/cmp/special.c b/usr.bin/cmp/special.c new file mode 100644 index 00000000000..4a25bb246e0 --- /dev/null +++ b/usr.bin/cmp/special.c @@ -0,0 +1,105 @@ +/* $NetBSD: special.c,v 1.2 1995/09/08 03:23:00 tls Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)special.c 8.3 (Berkeley) 4/2/94"; +#else +static char rcsid[] = "$NetBSD: special.c,v 1.2 1995/09/08 03:23:00 tls Exp $"; +#endif +#endif /* not lint */ + +#include <sys/types.h> + +#include <err.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "extern.h" + +void +c_special(fd1, file1, skip1, fd2, file2, skip2) + int fd1, fd2; + char *file1, *file2; + off_t skip1, skip2; +{ + int ch1, ch2; + off_t byte, line; + FILE *fp1, *fp2; + int dfound; + + if ((fp1 = fdopen(fd1, "r")) == NULL) + err(ERR_EXIT, "%s", file1); + if ((fp2 = fdopen(fd2, "r")) == NULL) + err(ERR_EXIT, "%s", file2); + + while (skip1--) + if (getc(fp1) == EOF) + goto eof; + while (skip2--) + if (getc(fp2) == EOF) + goto eof; + + dfound = 0; + for (byte = line = 1;; ++byte) { + ch1 = getc(fp1); + ch2 = getc(fp2); + if (ch1 == EOF || ch2 == EOF) + break; + if (ch1 != ch2) + if (lflag) { + dfound = 1; + (void)printf("%6qd %3o %3o\n", byte, ch1, ch2); + } else + diffmsg(file1, file2, byte, line); + /* NOTREACHED */ + if (ch1 == '\n') + ++line; + } + +eof: if (ferror(fp1)) + err(ERR_EXIT, "%s", file1); + if (ferror(fp2)) + err(ERR_EXIT, "%s", file2); + if (feof(fp1)) { + if (!feof(fp2)) + eofmsg(file1); + } else + if (feof(fp2)) + eofmsg(file2); + if (dfound) + exit(DIFF_EXIT); +} |