From 5b57d28ffb6e1ef86b50f7d05d977826eae89bfe Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Fri, 1 Feb 2019 22:55:37 +0000 Subject: initial population --- usr.bin/cmp/cmp.1 | 122 ++++++++++++++++++++++++++++++++++++ usr.bin/cmp/cmp.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++ usr.bin/cmp/extern.h | 44 +++++++++++++ usr.bin/cmp/misc.c | 84 +++++++++++++++++++++++++ usr.bin/cmp/regular.c | 118 +++++++++++++++++++++++++++++++++++ usr.bin/cmp/special.c | 111 +++++++++++++++++++++++++++++++++ 6 files changed, 647 insertions(+) create mode 100644 usr.bin/cmp/cmp.1 create mode 100644 usr.bin/cmp/cmp.c create mode 100644 usr.bin/cmp/extern.h create mode 100644 usr.bin/cmp/misc.c create mode 100644 usr.bin/cmp/regular.c create mode 100644 usr.bin/cmp/special.c (limited to 'usr.bin/cmp') diff --git a/usr.bin/cmp/cmp.1 b/usr.bin/cmp/cmp.1 new file mode 100644 index 0000000..e61f62c --- /dev/null +++ b/usr.bin/cmp/cmp.1 @@ -0,0 +1,122 @@ +.\" $NetBSD: cmp.1,v 1.13 2017/07/03 21:34:18 wiz 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. 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 December 13, 2016 +.Dt CMP 1 +.Os +.Sh NAME +.Nm cmp +.Nd compare two files +.Sh SYNOPSIS +.Nm +.Op Fl c +.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 c +Do the compare using +.Xr getc 3 +rather than +.Xr mmap 2 . +Combined with the +.Fl l +flag, this can be helpful in locating an I/O error in the underlying +device. +.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''. +.Sh EXIT STATUS +The +.Nm +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 +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 comm 1 , +.Xr diff 1 , +.Xr diff3 1 , +.Xr sdiff 1 +.Sh STANDARDS +The +.Nm +utility is expected to be +.St -p1003.2 +compatible. +.Sh HISTORY +The +.Nm +utility first appeared in +.At v1 . diff --git a/usr.bin/cmp/cmp.c b/usr.bin/cmp/cmp.c new file mode 100644 index 0000000..4301731 --- /dev/null +++ b/usr.bin/cmp/cmp.c @@ -0,0 +1,168 @@ +/* $NetBSD: cmp.c,v 1.20 2016/10/30 19:33:49 christos 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. 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. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1987, 1990, 1993, 1994\ + The Regents of the University of California. All rights reserved."); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmp.c 8.3 (Berkeley) 4/2/94"; +#else +__RCSID("$NetBSD: cmp.c,v 1.20 2016/10/30 19:33:49 christos Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "extern.h" + +int lflag, sflag; + +__dead static void usage(void); + +int +main(int argc, char *argv[]) +{ + struct stat sb1, sb2; + off_t skip1 = 0, skip2 = 0; + int ch, fd1, fd2, special; + const char *file1, *file2; + + setlocale(LC_ALL, ""); + + special = 0; + while ((ch = getopt(argc, argv, "cls")) != -1) + switch (ch) { + case 'c': + special = 1; /* careful! Don't use mmap() */ + break; + case 'l': /* print all differences */ + lflag = 1; + break; + case 's': /* silent run */ + sflag = 1; + break; + case '?': + default: + usage(); + } + 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. */ + if (strcmp(file1 = argv[0], "-") == 0) { + special = 1; + fd1 = 0; + file1 = "stdin"; + } + else if ((fd1 = open(file1, O_RDONLY, 0)) < 0) { + if (!sflag) + warn("%s", file1); + exit(ERR_EXIT); + } + 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) { + if (!sflag) + warn("%s", file2); + exit(ERR_EXIT); + } + + if (argc > 2) { + char *ep; + + errno = 0; + skip1 = strtoq(argv[2], &ep, 0); + if (errno || ep == argv[2]) + usage(); + + if (argc == 4) { + skip2 = strtoq(argv[3], &ep, 0); + if (errno || ep == argv[3]) + usage(); + } + } + + 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) +{ + + (void)fprintf(stderr, + "Usage: %s [-c] [-l | -s] file1 file2 [skip1 [skip2]]\n", + getprogname()); + exit(ERR_EXIT); +} diff --git a/usr.bin/cmp/extern.h b/usr.bin/cmp/extern.h new file mode 100644 index 0000000..d8a72ed --- /dev/null +++ b/usr.bin/cmp/extern.h @@ -0,0 +1,44 @@ +/* $NetBSD: extern.h,v 1.9 2011/08/29 14:14:11 joerg 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. 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(int, const char *, off_t, off_t, int, const char *, off_t, off_t); +void c_special(int, const char *, off_t, int, const char *, off_t); +__dead void diffmsg(const char *, const char *, off_t, off_t); +__dead void eofmsg(const char *, off_t, off_t); +__dead void errmsg(const char *, off_t, off_t); + +extern int lflag, sflag; diff --git a/usr.bin/cmp/misc.c b/usr.bin/cmp/misc.c new file mode 100644 index 0000000..3195de9 --- /dev/null +++ b/usr.bin/cmp/misc.c @@ -0,0 +1,84 @@ +/* $NetBSD: misc.c,v 1.12 2009/04/11 12:16:12 lukem 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. 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. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94"; +#else +__RCSID("$NetBSD: misc.c,v 1.12 2009/04/11 12:16:12 lukem Exp $"); +#endif +#endif /* not lint */ + +#include + +#include +#include +#include + +#include "extern.h" + +void +errmsg(const char *file, off_t byte, off_t line) +{ + if (lflag) + err(ERR_EXIT, "%s: char %lld, line %lld", file, + (long long)byte, (long long)line); + else + err(ERR_EXIT, "%s", file); +} + +void +eofmsg(const char *file, off_t byte, off_t line) +{ + if (!sflag) { + if (!lflag) + warnx("EOF on %s", file); + else { + if (line > 0) + warnx("EOF on %s: char %lld, line %lld", + file, (long long)byte, (long long)line); + else + warnx("EOF on %s: char %lld", + file, (long long)byte); + } + } + exit(DIFF_EXIT); +} + +void +diffmsg(const char *file1, const char *file2, off_t byte, off_t line) +{ + if (!sflag) + (void)printf("%s %s differ: char %lld, line %lld\n", + file1, file2, (long long)byte, (long long)line); + exit(DIFF_EXIT); +} diff --git a/usr.bin/cmp/regular.c b/usr.bin/cmp/regular.c new file mode 100644 index 0000000..63c663f --- /dev/null +++ b/usr.bin/cmp/regular.c @@ -0,0 +1,118 @@ +/* $NetBSD: regular.c,v 1.24 2013/11/20 17:19:14 kleink 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. 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. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)regular.c 8.3 (Berkeley) 4/2/94"; +#else +__RCSID("$NetBSD: regular.c,v 1.24 2013/11/20 17:19:14 kleink Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "extern.h" + +void +c_regular(int fd1, const char *file1, off_t skip1, off_t len1, + int fd2, const char *file2, off_t skip2, off_t len2) +{ + u_char ch, *p1, *p2; + off_t byte, length, line; + int dfound; + size_t blk_sz, blk_cnt; + + if (sflag && len1 != len2) + exit(1); + + if (skip1 > len1) + eofmsg(file1, len1 + 1, 0); + len1 -= skip1; + if (skip2 > len2) + eofmsg(file2, len2 + 1, 0); + len2 -= skip2; + + byte = line = 1; + dfound = 0; + length = MIN(len1, len2); + for (blk_sz = 1024 * 1024; length != 0; length -= blk_sz) { + if ((uintmax_t)blk_sz > (uintmax_t)length) + blk_sz = length; + p1 = mmap(NULL, blk_sz, PROT_READ, MAP_FILE|MAP_SHARED, + fd1, skip1); + if (p1 == MAP_FAILED) + goto mmap_failed; + + p2 = mmap(NULL, blk_sz, PROT_READ, MAP_FILE|MAP_SHARED, + fd2, skip2); + if (p2 == MAP_FAILED) { + munmap(p1, blk_sz); + goto mmap_failed; + } + + blk_cnt = blk_sz; + for (; blk_cnt--; ++p1, ++p2, ++byte) { + if ((ch = *p1) != *p2) { + if (!lflag) { + diffmsg(file1, file2, byte, line); + /* NOTREACHED */ + } + dfound = 1; + (void)printf("%6lld %3o %3o\n", + (long long)byte, ch, *p2); + } + if (ch == '\n') + ++line; + } + munmap(p1 - blk_sz, blk_sz); + munmap(p2 - blk_sz, blk_sz); + skip1 += blk_sz; + skip2 += blk_sz; + } + + if (len1 != len2) + eofmsg(len1 > len2 ? file2 : file1, byte, line); + if (dfound) + exit(DIFF_EXIT); + return; + +mmap_failed: + c_special(fd1, file1, skip1, fd2, file2, skip2); +} diff --git a/usr.bin/cmp/special.c b/usr.bin/cmp/special.c new file mode 100644 index 0000000..0b1afc5 --- /dev/null +++ b/usr.bin/cmp/special.c @@ -0,0 +1,111 @@ +/* $NetBSD: special.c,v 1.14 2011/11/28 10:10:10 wiz 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. 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. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)special.c 8.3 (Berkeley) 4/2/94"; +#else +__RCSID("$NetBSD: special.c,v 1.14 2011/11/28 10:10:10 wiz Exp $"); +#endif +#endif /* not lint */ + +#include + +#include +#include +#include + +#include "extern.h" + +void +c_special(int fd1, const char *file1, off_t skip1, int fd2, const char *file2, off_t skip2) +{ + int ch1, ch2; + off_t byte, line; + FILE *fp1, *fp2; + int dfound; + + dfound = 0; + if ((fp1 = fdopen(fd1, "r")) == NULL) + err(ERR_EXIT, "%s", file1); + if ((fp2 = fdopen(fd2, "r")) == NULL) + err(ERR_EXIT, "%s", file2); + + for (byte = line = 1; skip1--; byte++) { + ch1 = getc(fp1); + if (ch1 == EOF) + goto eof; + if (ch1 == '\n') + line++; + } + for (byte = line = 1; skip2--; byte++) { + ch2 = getc(fp2); + if (ch2 == EOF) + goto eof; + if (ch2 == '\n') + line++; + } + 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("%6lld %3o %3o\n", (long long)byte, + ch1, ch2); + } else + diffmsg(file1, file2, byte, line); + /* NOTREACHED */ + } + if (ch1 == '\n') + ++line; + } + + eof: + if (ferror(fp1)) + errmsg(file1, byte, line); + if (ferror(fp2)) + errmsg(file2, byte, line); + if (feof(fp1)) { + if (!feof(fp2)) + eofmsg(file1, byte, line); + } else + if (feof(fp2)) + eofmsg(file2, byte, line); + (void)fclose(fp1); + (void)fclose(fp2); + if (dfound) + exit(DIFF_EXIT); +} -- cgit v1.2.3-60-g2f50