slightly different semantics). Also clean up some gcc -Wall'isms.
-# $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>
-/* $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 $ */
/*-
* @(#)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();
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;
-/* $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 $ */
/*-
#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>
#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 *));
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);
}
}
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;
}
return;
}
if (munmap(start, (size_t)sbp->st_size)) {
- err(0, "%s: %s", fname, strerror(errno));
+ err(0, fname);
return;
}
}
+++ /dev/null
-/* $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;
-}
-/* $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 $ */
/*-
#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"
/*
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;
} else {
if (wrap && (len = ep - p))
WR(p, len);
- if (len = p - sp)
+ if ((len = p - sp))
WR(sp, len);
}
}
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;
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) {
-/* $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 $ */
/*-
#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 *));
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;
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 {
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;
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) {
if (enomem) {
(void)fprintf(stderr,
- "tail: warning: %ld bytes discarded\n", enomem);
+ "tail: warning: %qd bytes discarded\n", enomem);
rval = 1;
}
-/* $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
#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;
{
struct stat sb;
FILE *fp;
- long off;
+ long off = 0;
enum STYLE style;
int ch, first;
char *p;
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) \
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
}
if (*argv)
- for (first = 1; fname = *argv++;) {
+ for (first = 1; (fname = *argv++);) {
if ((fp = fopen(fname, "r")) == NULL ||
fstat(fileno(fp), &sb)) {
ierr();
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] != '+')
/* 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++ = '-';
/*
*p++ = 'n';
break;
default:
- err(1, "illegal option -- %s", *argv);
+ errx(1, "illegal option -- %s", *argv);
}
*p++ = *argv[0];
(void)strcpy(p, ap);