From 81bcfffaf588114f28fd95b18ca90affacc80ec2 Mon Sep 17 00:00:00 2001 From: charnier Date: Thu, 14 Aug 1997 06:48:59 +0000 Subject: [PATCH] Add usage() and use err(3). --- usr.bin/time/time.1 | 8 ++++---- usr.bin/time/time.c | 27 +++++++++++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/usr.bin/time/time.1 b/usr.bin/time/time.1 index 52b555e2386d..303309644cac 100644 --- a/usr.bin/time/time.1 +++ b/usr.bin/time/time.1 @@ -38,12 +38,12 @@ .Nm time .Nd time command execution .Sh SYNOPSIS -.Nm time +.Nm .Op Fl l .Ar command .Sh DESCRIPTION The -.Nm time +.Nm utility executes and times @@ -55,7 +55,7 @@ shell. After the .Ar command finishes, -.Nm time +.Nm writes to the standard error stream, (in seconds): the total time elapsed, @@ -75,7 +75,7 @@ structure are printed as well. The .Xr csh 1 has its own and syntactically different builtin version of -.Nm time. +.Nm time . The command described here is available as .Pa /usr/bin/time diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c index 52a5709f7482..fea1e5ac2841 100644 --- a/usr.bin/time/time.c +++ b/usr.bin/time/time.c @@ -32,13 +32,17 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1987, 1988, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include @@ -51,14 +55,16 @@ static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93"; #include #include +#include static int getstathz __P((void)); +static void usage __P((void)); +int main(argc, argv) int argc; char **argv; { - extern int optind; register int pid; int ch, status, lflag; struct timeval before, after; @@ -72,8 +78,7 @@ main(argc, argv) break; case '?': default: - fprintf(stderr, "usage: time [-l] command.\n"); - exit(1); + usage(); } if (!(argc -= optind)) @@ -83,12 +88,11 @@ main(argc, argv) gettimeofday(&before, (struct timezone *)NULL); switch(pid = vfork()) { case -1: /* error */ - perror("time"); - exit(1); + err(1, "time"); /* NOTREACHED */ case 0: /* child */ execvp(*argv, argv); - perror(*argv); + warn("%s", *argv); _exit(1); /* NOTREACHED */ } @@ -98,7 +102,7 @@ main(argc, argv) while (wait3(&status, 0, &ru) != pid); /* XXX use waitpid */ gettimeofday(&after, (struct timezone *)NULL); if (status&0377) - fprintf(stderr, "Command terminated abnormally.\n"); + warnx("command terminated abnormally"); after.tv_sec -= before.tv_sec; after.tv_usec -= before.tv_usec; if (after.tv_usec < 0) @@ -154,6 +158,13 @@ main(argc, argv) exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE); } +static void +usage() +{ + fprintf(stderr, "usage: time [-l] command\n"); + exit(1); +} + /* * Return the frequency of the kernel's statistics clock. */