summaryrefslogtreecommitdiff
path: root/usr.bin/tail
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/tail')
-rw-r--r--usr.bin/tail/Makefile4
-rw-r--r--usr.bin/tail/extern.h9
-rw-r--r--usr.bin/tail/forward.c20
-rw-r--r--usr.bin/tail/misc.c96
-rw-r--r--usr.bin/tail/read.c30
-rw-r--r--usr.bin/tail/reverse.c22
-rw-r--r--usr.bin/tail/tail.c23
7 files changed, 58 insertions, 146 deletions
diff --git a/usr.bin/tail/Makefile b/usr.bin/tail/Makefile
index f523042957c..42f7cd7cd10 100644
--- a/usr.bin/tail/Makefile
+++ b/usr.bin/tail/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.2 1996/06/26 05:40:14 deraadt Exp $
+# $OpenBSD: Makefile,v 1.3 1997/01/12 23:43:03 millert Exp $
# $NetBSD: Makefile,v 1.3 1994/11/23 07:41:55 jtc Exp $
PROG= tail
-SRCS= forward.c misc.c read.c reverse.c tail.c
+SRCS= forward.c read.c reverse.c tail.c
.include <bsd.prog.mk>
diff --git a/usr.bin/tail/extern.h b/usr.bin/tail/extern.h
index e1a57d062f1..3bcd1ad5e13 100644
--- a/usr.bin/tail/extern.h
+++ b/usr.bin/tail/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.2 1996/06/26 05:40:14 deraadt Exp $ */
+/* $OpenBSD: extern.h,v 1.3 1997/01/12 23:43:04 millert Exp $ */
/* $NetBSD: extern.h,v 1.3 1994/11/23 07:42:00 jtc Exp $ */
/*-
@@ -36,6 +36,9 @@
* @(#)extern.h 8.1 (Berkeley) 6/6/93
*/
+#define ierr() (err(0, fname))
+#define oerr() (err(1, "stdout"))
+
#define WR(p, size) \
if (write(STDOUT_FILENO, p, size) != size) \
oerr();
@@ -48,9 +51,5 @@ void reverse __P((FILE *, enum STYLE, long, struct stat *));
void bytes __P((FILE *, off_t));
void lines __P((FILE *, off_t));
-void err __P((int fatal, const char *fmt, ...));
-void ierr __P((void));
-void oerr __P((void));
-
extern int fflag, rflag, rval;
extern char *fname;
diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c
index 7e46d1ad5b5..ecaa977d93e 100644
--- a/usr.bin/tail/forward.c
+++ b/usr.bin/tail/forward.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: forward.c,v 1.3 1996/06/26 05:40:15 deraadt Exp $ */
+/* $OpenBSD: forward.c,v 1.4 1997/01/12 23:43:05 millert Exp $ */
/* $NetBSD: forward.c,v 1.7 1996/02/13 16:49:10 ghudson Exp $ */
/*-
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)forward.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: forward.c,v 1.3 1996/06/26 05:40:15 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: forward.c,v 1.4 1997/01/12 23:43:05 millert Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -49,13 +49,15 @@ static char rcsid[] = "$OpenBSD: forward.c,v 1.3 1996/06/26 05:40:15 deraadt Exp
#include <sys/time.h>
#include <sys/mman.h>
-#include <limits.h>
-#include <fcntl.h>
+#include <err.h>
#include <errno.h>
-#include <unistd.h>
+#include <fcntl.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+
#include "extern.h"
static void rlines __P((FILE *, long, struct stat *));
@@ -182,7 +184,7 @@ forward(fp, style, off, sbp)
second.tv_sec = 1;
second.tv_usec = 0;
if (select(0, NULL, NULL, NULL, &second) == -1)
- err(1, "select: %s", strerror(errno));
+ err(1, "select");
clearerr(fp);
}
}
@@ -204,13 +206,13 @@ rlines(fp, off, sbp)
return;
if (size > SIZE_T_MAX) {
- err(0, "%s: %s", fname, strerror(EFBIG));
+ errx(0, "%s: %s", fname, strerror(EFBIG));
return;
}
if ((start = mmap(NULL, (size_t)size,
PROT_READ, 0, fileno(fp), (off_t)0)) == (caddr_t)-1) {
- err(0, "%s: %s", fname, strerror(EFBIG));
+ errx(0, "%s: %s", fname, strerror(EFBIG));
return;
}
@@ -229,7 +231,7 @@ rlines(fp, off, sbp)
return;
}
if (munmap(start, (size_t)sbp->st_size)) {
- err(0, "%s: %s", fname, strerror(errno));
+ err(0, fname);
return;
}
}
diff --git a/usr.bin/tail/misc.c b/usr.bin/tail/misc.c
deleted file mode 100644
index bdc77c9efb1..00000000000
--- a/usr.bin/tail/misc.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/* $OpenBSD: misc.c,v 1.2 1996/06/26 05:40:16 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Edward Sze-Tyan Wang.
- *
- * 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.1 (Berkeley) 6/6/93";
-#endif
-static char rcsid[] = "$OpenBSD: misc.c,v 1.2 1996/06/26 05:40:16 deraadt Exp $";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "extern.h"
-
-void
-ierr()
-{
- err(0, "%s: %s", fname, strerror(errno));
-}
-
-void
-oerr()
-{
- err(1, "stdout: %s", strerror(errno));
-}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(int fatal, const char *fmt, ...)
-#else
-err(fatal, fmt, va_alist)
- int fatal;
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "tail: ");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
- if (fatal)
- exit(1);
- rval = 1;
-}
diff --git a/usr.bin/tail/read.c b/usr.bin/tail/read.c
index 14adc658199..f84bd9d24f9 100644
--- a/usr.bin/tail/read.c
+++ b/usr.bin/tail/read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: read.c,v 1.2 1996/06/26 05:40:16 deraadt Exp $ */
+/* $OpenBSD: read.c,v 1.3 1997/01/12 23:43:06 millert Exp $ */
/* $NetBSD: read.c,v 1.4 1994/11/23 07:42:07 jtc Exp $ */
/*-
@@ -41,17 +41,20 @@
#if 0
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: read.c,v 1.2 1996/06/26 05:40:16 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: read.c,v 1.3 1997/01/12 23:43:06 millert Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
-#include <fcntl.h>
+
+#include <err.h>
#include <errno.h>
-#include <unistd.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+
#include "extern.h"
/*
@@ -75,7 +78,7 @@ bytes(fp, off)
char *sp;
if ((sp = p = malloc(off)) == NULL)
- err(1, "%s", strerror(errno));
+ err(1, NULL);
for (wrap = 0, ep = p + off; (ch = getc(fp)) != EOF;) {
*p = ch;
@@ -116,7 +119,7 @@ bytes(fp, off)
} else {
if (wrap && (len = ep - p))
WR(p, len);
- if (len = p - sp)
+ if ((len = p - sp))
WR(sp, len);
}
}
@@ -142,20 +145,19 @@ lines(fp, off)
char *l;
} *lines;
register int ch;
- register char *p;
+ register char *p = NULL;
int blen, cnt, recno, wrap;
- char *sp;
+ char *sp = NULL;
- if ((lines = malloc(off * sizeof(*lines))) == NULL)
- err(1, "%s", strerror(errno));
+ if ((lines = calloc(off, sizeof(*lines))) == NULL)
+ err(1, NULL);
- sp = NULL;
blen = cnt = recno = wrap = 0;
while ((ch = getc(fp)) != EOF) {
if (++cnt > blen) {
if ((sp = realloc(sp, blen += 1024)) == NULL)
- err(1, "%s", strerror(errno));
+ err(1, NULL);
p = sp + cnt - 1;
}
*p++ = ch;
@@ -164,9 +166,9 @@ lines(fp, off)
lines[recno].blen = cnt + 256;
if ((lines[recno].l = realloc(lines[recno].l,
lines[recno].blen)) == NULL)
- err(1, "%s", strerror(errno));
+ err(1, NULL);
}
- bcopy(sp, lines[recno].l, lines[recno].len = cnt);
+ memcpy(lines[recno].l, sp, (lines[recno].len = cnt));
cnt = 0;
p = sp;
if (++recno == off) {
diff --git a/usr.bin/tail/reverse.c b/usr.bin/tail/reverse.c
index 6e3a28f18a3..9711616978b 100644
--- a/usr.bin/tail/reverse.c
+++ b/usr.bin/tail/reverse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: reverse.c,v 1.2 1996/06/26 05:40:17 deraadt Exp $ */
+/* $OpenBSD: reverse.c,v 1.3 1997/01/12 23:43:06 millert Exp $ */
/* $NetBSD: reverse.c,v 1.6 1994/11/23 07:42:10 jtc Exp $ */
/*-
@@ -41,19 +41,21 @@
#if 0
static char sccsid[] = "@(#)reverse.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: reverse.c,v 1.2 1996/06/26 05:40:17 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: reverse.c,v 1.3 1997/01/12 23:43:06 millert Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/mman.h>
-#include <limits.h>
+#include <err.h>
#include <errno.h>
-#include <unistd.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+
#include "extern.h"
static void r_buf __P((FILE *));
@@ -124,13 +126,13 @@ r_reg(fp, style, off, sbp)
return;
if (size > SIZE_T_MAX) {
- err(0, "%s: %s", fname, strerror(EFBIG));
+ errx(0, "%s: %s", fname, strerror(EFBIG));
return;
}
if ((start = mmap(NULL, (size_t)size,
PROT_READ, 0, fileno(fp), (off_t)0)) == (caddr_t)-1) {
- err(0, "%s: %s", fname, strerror(EFBIG));
+ errx(0, "%s: %s", fname, strerror(EFBIG));
return;
}
p = start + size - 1;
@@ -151,7 +153,7 @@ r_reg(fp, style, off, sbp)
if (llen)
WR(p, llen);
if (munmap(start, (size_t)sbp->st_size))
- err(0, "%s: %s", fname, strerror(errno));
+ err(0, fname);
}
typedef struct bf {
@@ -175,7 +177,7 @@ static void
r_buf(fp)
FILE *fp;
{
- register BF *mark, *tl, *tr;
+ register BF *mark, *tr, *tl = NULL;
register int ch, len, llen;
register char *p;
off_t enomem;
@@ -190,7 +192,7 @@ r_buf(fp)
if (enomem || (tl = malloc(sizeof(BF))) == NULL ||
(tl->l = malloc(BSZ)) == NULL) {
if (!mark)
- err(1, "%s", strerror(errno));
+ err(1, NULL);
tl = enomem ? tl->next : mark;
enomem += tl->len;
} else if (mark) {
@@ -224,7 +226,7 @@ r_buf(fp)
if (enomem) {
(void)fprintf(stderr,
- "tail: warning: %ld bytes discarded\n", enomem);
+ "tail: warning: %qd bytes discarded\n", enomem);
rval = 1;
}
diff --git a/usr.bin/tail/tail.c b/usr.bin/tail/tail.c
index da7436244ad..aca36d6baab 100644
--- a/usr.bin/tail/tail.c
+++ b/usr.bin/tail/tail.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tail.c,v 1.2 1996/06/26 05:40:18 deraadt Exp $ */
+/* $OpenBSD: tail.c,v 1.3 1997/01/12 23:43:07 millert Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -46,16 +46,19 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)tail.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: tail.c,v 1.2 1996/06/26 05:40:18 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: tail.c,v 1.3 1997/01/12 23:43:07 millert Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
+
+#include <err.h>
#include <errno.h>
-#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+
#include "extern.h"
int fflag, rflag, rval;
@@ -71,7 +74,7 @@ main(argc, argv)
{
struct stat sb;
FILE *fp;
- long off;
+ long off = 0;
enum STYLE style;
int ch, first;
char *p;
@@ -93,7 +96,7 @@ main(argc, argv)
usage(); \
off = strtol(optarg, &p, 10) * (units); \
if (*p) \
- err(1, "illegal offset -- %s", optarg); \
+ errx(1, "illegal offset -- %s", optarg); \
switch(optarg[0]) { \
case '+': \
if (off) \
@@ -136,7 +139,7 @@ main(argc, argv)
argv += optind;
if (fflag && argc > 1)
- err(1, "-f option only appropriate for a single file");
+ errx(1, "-f option only appropriate for a single file");
/*
* If displaying in reverse, don't permit follow option, and convert
@@ -165,7 +168,7 @@ main(argc, argv)
}
if (*argv)
- for (first = 1; fname = *argv++;) {
+ for (first = 1; (fname = *argv++);) {
if ((fp = fopen(fname, "r")) == NULL ||
fstat(fileno(fp), &sb)) {
ierr();
@@ -223,7 +226,7 @@ obsolete(argv)
int len;
char *start;
- while (ap = *++argv) {
+ while ((ap = *++argv)) {
/* Return if "--" or not an option of any form. */
if (ap[0] != '-') {
if (ap[0] != '+')
@@ -239,7 +242,7 @@ obsolete(argv)
/* Malloc space for dash, new option and argument. */
len = strlen(*argv);
if ((start = p = malloc(len + 3)) == NULL)
- err(1, "%s", strerror(errno));
+ err(1, NULL);
*p++ = '-';
/*
@@ -269,7 +272,7 @@ obsolete(argv)
*p++ = 'n';
break;
default:
- err(1, "illegal option -- %s", *argv);
+ errx(1, "illegal option -- %s", *argv);
}
*p++ = *argv[0];
(void)strcpy(p, ap);