Add usage() and use err(3).

This commit is contained in:
Philippe Charnier 1997-08-14 06:48:59 +00:00
parent fd129a0245
commit 80c486a414
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28203
2 changed files with 23 additions and 12 deletions

View File

@ -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

View File

@ -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 <sys/types.h>
@ -51,14 +55,16 @@ static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93";
#include <err.h>
#include <stdio.h>
#include <unistd.h>
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.
*/