Module Name: src Committed By: christos Date: Sat Sep 3 09:02:20 UTC 2011
Modified Files: src/usr.bin/tail: extern.h forward.c misc.c read.c reverse.c tail.c Log Message: Instead of declaring our own err() which is different than the standard one, and using it incorrectly in a few places because of confusion (does it print errno or not?), declare two versions following the standard ones xerrx and, xerr, and use those as appropriate, implementing them using them vwarn and vwarnx. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.bin/tail/extern.h cvs rdiff -u -r1.29 -r1.30 src/usr.bin/tail/forward.c cvs rdiff -u -r1.6 -r1.7 src/usr.bin/tail/misc.c cvs rdiff -u -r1.15 -r1.16 src/usr.bin/tail/read.c cvs rdiff -u -r1.20 -r1.21 src/usr.bin/tail/reverse.c cvs rdiff -u -r1.14 -r1.15 src/usr.bin/tail/tail.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/tail/extern.h diff -u src/usr.bin/tail/extern.h:1.9 src/usr.bin/tail/extern.h:1.10 --- src/usr.bin/tail/extern.h:1.9 Mon Apr 13 19:33:25 2009 +++ src/usr.bin/tail/extern.h Sat Sep 3 05:02:20 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.9 2009/04/13 23:33:25 lukem Exp $ */ +/* $NetBSD: extern.h,v 1.10 2011/09/03 09:02:20 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -43,8 +43,8 @@ int displaybytes(FILE *, off_t); int displaylines(FILE *, off_t); -void err(int fatal, const char *fmt, ...) - __attribute__((__format__(__printf__, 2, 3))); +void xerr(int fatal, const char *fmt, ...) __printflike(2, 3); +void xerrx(int fatal, const char *fmt, ...) __printflike(2, 3); void ierr(void); void oerr(void); Index: src/usr.bin/tail/forward.c diff -u src/usr.bin/tail/forward.c:1.29 src/usr.bin/tail/forward.c:1.30 --- src/usr.bin/tail/forward.c:1.29 Mon Apr 13 19:33:25 2009 +++ src/usr.bin/tail/forward.c Sat Sep 3 05:02:20 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: forward.c,v 1.29 2009/04/13 23:33:25 lukem Exp $ */ +/* $NetBSD: forward.c,v 1.30 2011/09/03 09:02:20 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)forward.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: forward.c,v 1.29 2009/04/13 23:33:25 lukem Exp $"); +__RCSID("$NetBSD: forward.c,v 1.30 2011/09/03 09:02:20 christos Exp $"); #endif /* not lint */ #include <sys/types.h> @@ -180,7 +180,7 @@ if (fflag) { kq = kqueue(); if (kq < 0) - err(1, "kqueue"); + xerr(1, "kqueue"); action = ADD_EVENTS; } @@ -225,7 +225,7 @@ case USE_KQUEUE: if (kevent(kq, NULL, 0, ev, 1, NULL) < 0) - err(1, "kevent"); + xerr(1, "kevent"); if (ev[0].filter == EVFILT_VNODE) { /* file was rotated, wait until it reappears */ @@ -305,7 +305,7 @@ start = mmap(NULL, (size_t)mmap_size, PROT_READ, MAP_FILE|MAP_SHARED, fileno(fp), mmap_offset); if (start == MAP_FAILED) { - err(0, "%s: %s", fname, strerror(EFBIG)); + xerr(0, "%s", fname); return (1); } @@ -326,7 +326,7 @@ break; if (munmap(start, mmap_size)) { - err(0, "%s: %s", fname, strerror(errno)); + xerr(0, "%s", fname); return (1); } @@ -344,7 +344,7 @@ WR(p, mmap_size - mmap_remaining); file_remaining += mmap_size - mmap_remaining; if (munmap(start, mmap_size)) { - err(0, "%s: %s", fname, strerror(errno)); + xerr(0, "%s", fname); return (1); } Index: src/usr.bin/tail/misc.c diff -u src/usr.bin/tail/misc.c:1.6 src/usr.bin/tail/misc.c:1.7 --- src/usr.bin/tail/misc.c:1.6 Thu Aug 7 07:16:02 2003 +++ src/usr.bin/tail/misc.c Sat Sep 3 05:02:20 2011 @@ -35,7 +35,7 @@ #if 0 static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: misc.c,v 1.6 2003/08/07 11:16:02 agc Exp $"); +__RCSID("$NetBSD: misc.c,v 1.7 2011/09/03 09:02:20 christos Exp $"); #endif /* not lint */ #include <sys/types.h> @@ -46,31 +46,43 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <err.h> #include "extern.h" void ierr(void) { - err(0, "%s: %s", fname, strerror(errno)); + xerr(0, "%s", fname); } void oerr(void) { - err(1, "stdout: %s", strerror(errno)); + xerr(1, "stdout"); } void -err(int fatal, const char *fmt, ...) +xerr(int fatal, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - (void)fprintf(stderr, "tail: "); - (void)vfprintf(stderr, fmt, ap); + vwarn(fmt, ap); + va_end(ap); + if (fatal) + exit(1); + rval = 1; +} + +void +xerrx(int fatal, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vwarnx(fmt, ap); va_end(ap); - (void)fprintf(stderr, "\n"); if (fatal) exit(1); rval = 1; Index: src/usr.bin/tail/read.c diff -u src/usr.bin/tail/read.c:1.15 src/usr.bin/tail/read.c:1.16 --- src/usr.bin/tail/read.c:1.15 Mon Apr 13 19:33:25 2009 +++ src/usr.bin/tail/read.c Sat Sep 3 05:02:20 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.15 2009/04/13 23:33:25 lukem Exp $ */ +/* $NetBSD: read.c,v 1.16 2011/09/03 09:02:20 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: read.c,v 1.15 2009/04/13 23:33:25 lukem Exp $"); +__RCSID("$NetBSD: read.c,v 1.16 2011/09/03 09:02:20 christos Exp $"); #endif /* not lint */ #include <sys/types.h> @@ -71,7 +71,7 @@ char *sp; if ((sp = p = malloc(off)) == NULL) - err(1, "%s", strerror(errno)); + xerr(1, "malloc"); for (wrap = 0, ep = p + off; (ch = getc(fp)) != EOF;) { *p = ch; @@ -145,7 +145,7 @@ p = NULL; if ((lines = malloc(off * sizeof(*lines))) == NULL) - err(1, "%s", strerror(errno)); + xerr(1, "malloc"); memset(lines, 0, sizeof(*lines) * off); @@ -155,7 +155,7 @@ while ((ch = getc(fp)) != EOF) { if (++cnt > blen) { if ((n = realloc(sp, blen + 1024)) == NULL) - err(1, "%s", strerror(errno)); + xerr(1, "realloc"); sp = n; blen += 1024; p = sp + cnt - 1; @@ -165,7 +165,7 @@ if (lines[recno].blen < cnt) { if ((n = realloc(lines[recno].l, cnt + 256)) == NULL) - err(1, "%s", strerror(errno)); + xerr(1, "realloc"); lines[recno].l = n; lines[recno].blen = cnt + 256; } Index: src/usr.bin/tail/reverse.c diff -u src/usr.bin/tail/reverse.c:1.20 src/usr.bin/tail/reverse.c:1.21 --- src/usr.bin/tail/reverse.c:1.20 Mon Apr 13 19:33:25 2009 +++ src/usr.bin/tail/reverse.c Sat Sep 3 05:02:20 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: reverse.c,v 1.20 2009/04/13 23:33:25 lukem Exp $ */ +/* $NetBSD: reverse.c,v 1.21 2011/09/03 09:02:20 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)reverse.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: reverse.c,v 1.20 2009/04/13 23:33:25 lukem Exp $"); +__RCSID("$NetBSD: reverse.c,v 1.21 2011/09/03 09:02:20 christos Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -115,13 +115,15 @@ if ((uint64_t)size > SIZE_T_MAX) { /* XXX: need a cleaner way to check this on amd64 */ - err(0, "%s: %s", fname, strerror(EFBIG)); + errno = EFBIG; + xerr(0, "%s", fname); return; } if ((start = mmap(NULL, (size_t)size, PROT_READ, MAP_FILE|MAP_SHARED, fileno(fp), (off_t)0)) == (caddr_t)-1) { - err(0, "%s: %s", fname, strerror(EFBIG)); + errno = EFBIG; + xerr(0, "%s", fname); return; } p = start + size - 1; @@ -142,7 +144,7 @@ if (llen) WR(p, llen); if (munmap(start, (size_t)sbp->st_size)) - err(0, "%s: %s", fname, strerror(errno)); + xerr(0, "%s", fname); } typedef struct bf { @@ -181,7 +183,7 @@ if (enomem) { if (!mark) { errno = ENOMEM; - err(1, NULL); + xerr(1, NULL); } tl = tl->next; enomem += tl->len; @@ -191,7 +193,7 @@ free(tl); if (!mark) { errno = ENOMEM; - err(1, NULL); + xerr(1, NULL); } tl = mark; enomem += tl->len; Index: src/usr.bin/tail/tail.c diff -u src/usr.bin/tail/tail.c:1.14 src/usr.bin/tail/tail.c:1.15 --- src/usr.bin/tail/tail.c:1.14 Mon Apr 13 19:33:25 2009 +++ src/usr.bin/tail/tail.c Sat Sep 3 05:02:20 2011 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)tail.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: tail.c,v 1.14 2009/04/13 23:33:25 lukem Exp $"); +__RCSID("$NetBSD: tail.c,v 1.15 2011/09/03 09:02:20 christos Exp $"); #endif /* not lint */ #include <sys/types.h> @@ -87,7 +87,7 @@ usage(); \ off = strtoll(optarg, &p, 10) * (units); \ if (*p) \ - err(1, "illegal offset -- %s", optarg); \ + xerrx(1, "illegal offset -- %s", optarg); \ switch(optarg[0]) { \ case '+': \ if (off) \ @@ -133,7 +133,7 @@ argv += optind; if (fflag && argc > 1) - err(1, "-f and -F options only appropriate for a single file"); + xerrx(1, "-f and -F options only appropriate for a single file"); /* * If displaying in reverse, don't permit follow option, and convert @@ -235,7 +235,7 @@ /* Malloc space for dash, new option and argument. */ len = strlen(*argv); if ((start = p = malloc(len + 3)) == NULL) - err(1, "%s", strerror(errno)); + xerr(1, "malloc"); *p++ = '-'; /* @@ -265,7 +265,7 @@ *p++ = 'n'; break; default: - err(1, "illegal option -- %s", *argv); + xerrx(1, "illegal option -- %s", *argv); } *p++ = *argv[0]; (void)strcpy(p, ap);