From c10d7afbab992f7ee6ad49c0457e2c57e1f13212 Mon Sep 17 00:00:00 2001 From: Philippe Charnier Date: Thu, 14 Aug 1997 06:42:43 +0000 Subject: [PATCH] Use err(3) instead of local redefinition. Add usage(). --- usr.bin/tee/tee.1 | 15 +++++------ usr.bin/tee/tee.c | 65 ++++++++++++++++------------------------------- 2 files changed, 29 insertions(+), 51 deletions(-) diff --git a/usr.bin/tee/tee.1 b/usr.bin/tee/tee.1 index 2e453cb4fa9a..5b6cdd400377 100644 --- a/usr.bin/tee/tee.1 +++ b/usr.bin/tee/tee.1 @@ -41,12 +41,12 @@ .Nm tee .Nd pipe fitting .Sh SYNOPSIS -.Nm tee +.Nm .Op Fl ai -.Op Ar file ... +.Op Ar .Sh DESCRIPTION The -.Nm tee +.Nm utility copies standard input to standard output, making a copy in zero or more files. The output is unbuffered. @@ -64,25 +64,24 @@ signal. .Pp The following operands are available: .Bl -tag -width file -.It file +.It Ar file A pathname of an output .Ar file . .El .Pp The -.Nm tee +.Nm utility takes the default action for all signals, except in the event of the .Fl i option. .Pp The -.Nm tee +.Nm utility exits 0 on success, and >0 if an error occurs. .Sh STANDARDS The -.Nm tee +.Nm function is expected to be -.Tn POSIX .St -p1003.2 compatible. diff --git a/usr.bin/tee/tee.c b/usr.bin/tee/tee.c index 1008973b6d26..d844c5b00ba4 100644 --- a/usr.bin/tee/tee.c +++ b/usr.bin/tee/tee.c @@ -32,24 +32,28 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1988, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)tee.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include #include -#include -#include +#include #include -#include +#include #include #include #include +#include typedef struct _list { struct _list *next; @@ -59,7 +63,7 @@ typedef struct _list { LIST *head; void add __P((int, char *)); -void err __P((int, const char *, ...)); +static void usage __P((void)); int main(argc, argv) @@ -84,21 +88,20 @@ main(argc, argv) break; case '?': default: - (void)fprintf(stderr, "usage: tee [-ai] [file ...]\n"); - exit(1); + usage(); } argv += optind; argc -= optind; if ((buf = malloc((u_int)BSIZE)) == NULL) - err(1, "%s", strerror(errno)); + errx(1, "malloc"); add(STDOUT_FILENO, "stdout"); for (exitval = 0; *argv; ++argv) if ((fd = open(*argv, append ? O_WRONLY|O_CREAT|O_APPEND : O_WRONLY|O_CREAT|O_TRUNC, DEFFILEMODE)) < 0) { - err(0, "%s: %s", *argv, strerror(errno)); + warn("%s", *argv); exitval = 1; } else add(fd, *argv); @@ -109,8 +112,7 @@ main(argc, argv) bp = buf; do { if ((wval = write(p->fd, bp, n)) == -1) { - err(0, "%s: %s", - p->name, strerror(errno)); + warn("%s", p->name); exitval = 1; break; } @@ -118,10 +120,17 @@ main(argc, argv) } while (n -= wval); } if (rval < 0) - err(1, "read: %s", strerror(errno)); + err(1, "read"); exit(exitval); } +static void +usage() +{ + (void)fprintf(stderr, "usage: tee [-ai] [file ...]\n"); + exit(1); +} + void add(fd, name) int fd; @@ -130,39 +139,9 @@ add(fd, name) LIST *p; if ((p = malloc((u_int)sizeof(LIST))) == NULL) - err(1, "%s", strerror(errno)); + errx(1, "malloc"); p->fd = fd; p->name = name; p->next = head; head = p; } - -#if __STDC__ -#include -#else -#include -#endif - -void -#if __STDC__ -err(int doexit, const char *fmt, ...) -#else -err(doexit, fmt, va_alist) - int doexit; - char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)fprintf(stderr, "tee: "); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - if (doexit) - exit(1); -}