aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorPhilippe Charnier <charnier@FreeBSD.org>1997-08-14 06:48:59 +0000
committerPhilippe Charnier <charnier@FreeBSD.org>1997-08-14 06:48:59 +0000
commit80c486a414a506ad9850ca9317feb3763ac81fdc (patch)
treefcdef6c2937a5acd67ef78041edf5294f761228f /usr.bin
parentfd129a0245ccdbed26aee4a48cd7d4b2fa74a99d (diff)
downloadsrc-80c486a414a506ad9850ca9317feb3763ac81fdc.tar.gz
src-80c486a414a506ad9850ca9317feb3763ac81fdc.zip
Add usage() and use err(3).
Notes
Notes: svn path=/head/; revision=28203
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/time/time.18
-rw-r--r--usr.bin/time/time.c27
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 <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.
*/