-.\" $NetBSD: progress.1,v 1.12 2007/04/12 06:31:20 lukem Exp $
+.\" $NetBSD: progress.1,v 1.13 2007/06/06 17:49:14 briggs Exp $
.\"
.\" Copyright (c) 2003-2007 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd April 12, 2007
+.Dd June 6, 2007
.Dt PROGRESS 1
.Os
.Sh NAME
.Sh SYNOPSIS
.Nm
.Op Fl ez
+.Op Fl b Ar buffersize
.Op Fl f Ar file
.Op Fl l Ar length
.Op Fl p Ar prefix
.Pp
The options are as follows:
.Bl -tag -width XlXlengthXX
+.It Fl b Ar buffersize
+Read in buffers of the specified size (default 64k).
+An optional suffix (per
+.Xr strsuftoll 3 )
+may be given.
.It Fl e
Display progress to standard error instead of standard output.
.It Fl f Ar file
-/* $NetBSD: progress.c,v 1.14 2007/02/07 15:21:21 hubertf Exp $ */
+/* $NetBSD: progress.c,v 1.15 2007/06/06 17:49:14 briggs Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: progress.c,v 1.14 2007/02/07 15:21:21 hubertf Exp $");
+__RCSID("$NetBSD: progress.c,v 1.15 2007/06/06 17:49:14 briggs Exp $");
#endif /* not lint */
#include <sys/types.h>
usage(void)
{
fprintf(stderr,
- "usage: %s [-ez] [-f file] [-l length] [-p prefix] cmd [args...]\n",
- getprogname());
+ "usage: %s [-ez] [-b buffersize] [-f file] [-l length]\n"
+ " %*.s [-p prefix] cmd [args...]\n",
+ getprogname(), (int) strlen(getprogname()), "");
exit(EXIT_FAILURE);
}
int
main(int argc, char *argv[])
{
- static char fb_buf[BUFSIZ];
+ char *fb_buf;
char *infile = NULL;
pid_t pid = 0, gzippid = 0, deadpid;
int ch, fd, outpipe[2];
int ws, gzipstat, cmdstat;
int eflag = 0, lflag = 0, zflag = 0;
ssize_t nr, nw, off;
+ size_t buffersize;
struct stat statb;
struct ttysize ts;
/* defaults: Read from stdin, 0 filesize (no completion estimate) */
fd = STDIN_FILENO;
filesize = 0;
+ buffersize = 64 * 1024;
prefix = NULL;
- while ((ch = getopt(argc, argv, "ef:l:p:z")) != -1)
+ while ((ch = getopt(argc, argv, "b:ef:l:p:z")) != -1)
switch (ch) {
+ case 'b':
+ buffersize = (size_t) strsuftoll("buffer size", optarg,
+ 0, SIZE_T_MAX);
+ break;
case 'e':
eflag++;
break;
else
ttywidth = ts.ts_cols;
+ fb_buf = malloc(buffersize);
+ if (fb_buf == NULL)
+ err(1, "malloc for buffersize");
+
if (pipe(outpipe) < 0)
err(1, "output pipe");
pid = fork();
close(outpipe[0]);
progressmeter(-1);
- while ((nr = read(fd, fb_buf, BUFSIZ)) > 0)
+ while ((nr = read(fd, fb_buf, buffersize)) > 0)
for (off = 0; nr; nr -= nw, off += nw, bytes += nw)
if ((nw = write(outpipe[1], fb_buf + off,
(size_t) nr)) < 0)
}
progressmeter(1);
+
+ free(fb_buf);
+
exit(cmdstat ? cmdstat : gzipstat);
}