summaryrefslogtreecommitdiffstats
path: root/usr.bin/time
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>1998-07-27 16:08:58 +0000
committerdes <des@FreeBSD.org>1998-07-27 16:08:58 +0000
commit3f4090e1b74c9bd804e625d65274580eaca5d5cd (patch)
tree734d0d13f53466fa281b18d6c6fbc557a732d8fc /usr.bin/time
parent1881ba1352f6c65e59d5ca9547c3b0d7067e65b5 (diff)
downloadFreeBSD-src-3f4090e1b74c9bd804e625d65274580eaca5d5cd.zip
FreeBSD-src-3f4090e1b74c9bd804e625d65274580eaca5d5cd.tar.gz
Clean up the previous commit.
Diffstat (limited to 'usr.bin/time')
-rw-r--r--usr.bin/time/time.132
-rw-r--r--usr.bin/time/time.c48
2 files changed, 45 insertions, 35 deletions
diff --git a/usr.bin/time/time.1 b/usr.bin/time/time.1
index b095281..a3f805f 100644
--- a/usr.bin/time/time.1
+++ b/usr.bin/time/time.1
@@ -40,7 +40,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl a Ar file
-.Op Fl f Ar file
+.Op Fl o Ar file
.Op Fl l
.Ar command
.Sh DESCRIPTION
@@ -74,22 +74,14 @@ Append the output of
to
.Ar file
instead of writing to stderr.
-.It Fl f Ar file
+.It Fl o Ar file
Write the output to
.Ar file
instead of stderr. If
.Ar file
exists, then
.Nm
-will overwrite the file if premissions permit such an operation.
-The output can be sent to stdout by giving
-a file name
-.Do
--
-.Dc
-to the
-.Fl f
-option.
+will overwrite the file if its permissions allow it.
.It Fl l
The contents of the
.Em rusage
@@ -106,6 +98,24 @@ is available as
to
.Xr csh
users.
+.Sh NOTES
+The output of
+.Nm
+can be directed to standard output by specifying
+.Do
+-
+.Dc
+as the argument to the
+.Fl a
+or
+.Fl o
+option.
+.Pp
+The
+.Fl a
+and
+.Fl o
+options are mutually exclusive.
.Sh BUGS
The granularity of seconds on micro processors is crude and
can result in times being reported for CPU usage which are too large by
diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c
index ff703fd..6aa698f 100644
--- a/usr.bin/time/time.c
+++ b/usr.bin/time/time.c
@@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
- "$Id: time.c,v 1.6 1997/08/14 06:48:59 charnier Exp $";
+ "$Id: time.c,v 1.7 1998/07/24 07:19:29 phk Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -55,8 +55,9 @@ static const char rcsid[] =
#include <err.h>
#include <stdio.h>
-#include <unistd.h>
#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
static int getstathz __P((void));
static void usage __P((void));
@@ -70,31 +71,25 @@ main(argc, argv)
extern int optind;
register int pid;
- int ch, status, lflag;
+ int ch, status, lflag, aflag = 0;
struct timeval before, after;
struct rusage ru;
- FILE *out = NULL;
+ FILE *out = stderr;
+ char *ofn = NULL;
lflag = 0;
- while ((ch = getopt(argc, argv, "a:f:l")) != -1)
+ while ((ch = getopt(argc, argv, "a:o:l")) != -1)
switch((char)ch) {
case 'a':
- if (out)
- err(1, optarg);
- out = fopen(optarg, "a");
- if (!out)
- err(1, optarg);
+ if (ofn)
+ usage();
+ ofn = optarg;
+ aflag = 1;
break;
- case 'f':
- if (out)
- err(1, optarg);
- if (strcmp(optarg, "-") == 0)
- out = stdout;
- else {
- out = fopen(optarg, "w");
- if (!out)
- err(1, optarg);
- }
+ case 'o':
+ if (ofn)
+ usage();
+ ofn = optarg;
break;
case 'l':
lflag = 1;
@@ -108,8 +103,13 @@ main(argc, argv)
exit(0);
argv += optind;
- if (!out)
- out = stderr;
+ if (ofn) {
+ if (strcmp(ofn, "-") == 0)
+ out = stdout;
+ else
+ if ((out = fopen(ofn, aflag?"a":"w")) == NULL)
+ err(EX_IOERR, ofn);
+ }
gettimeofday(&before, (struct timezone *)NULL);
switch(pid = vfork()) {
@@ -187,8 +187,8 @@ main(argc, argv)
static void
usage()
{
- fprintf(stderr, "usage: time [-l] command\n");
- exit(1);
+ fprintf(stderr, "usage: time [-l] [-{o|a} file] command\n");
+ exit(EX_USAGE);
}
/*
OpenPOWER on IntegriCloud