summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-08-14 06:48:59 +0000
committercharnier <charnier@FreeBSD.org>1997-08-14 06:48:59 +0000
commit81bcfffaf588114f28fd95b18ca90affacc80ec2 (patch)
tree7e428ddf21060b8ac4c893505eb806b20d75760c /usr.bin
parent1cc1919e6eb5e2daabdd40ceb62c0edd333a9533 (diff)
downloadFreeBSD-src-81bcfffaf588114f28fd95b18ca90affacc80ec2.zip
FreeBSD-src-81bcfffaf588114f28fd95b18ca90affacc80ec2.tar.gz
Add usage() and use err(3).
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 52b555e..3033096 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 52a5709..fea1e5a 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.
*/
OpenPOWER on IntegriCloud