Applied patch from Dave Beckett to support "@filename" as a "--size" argument.

This commit is contained in:
Andrew Wood
2023-07-16 11:07:06 +01:00
parent ff5efbe3eb
commit 0d1d5b77ec
4 changed files with 43 additions and 4 deletions
+2 -1
View File
@@ -74,6 +74,7 @@ is acknowledged and greatly appreciated:
* Jakub Wilk <jwilk@jwilk.net> - corrected README encoding
* [ikasty](https://github.com/ikasty) - added relative filename display to "`--watchfd`"
* [Michael Weiß](https://github.com/quitschbo) - corrected behaviour when not attached to a terminal
* [christoph-zededa](https://github.com/christoph-zededa) - provided OS X suppot for "`--watchfd`"
* [christoph-zededa](https://github.com/christoph-zededa) - provided OS X support for "`--watchfd`"
* [Dave Beckett](https://github.com/dajobe)) - added "`@filename`" syntax to "`--size`"
---
+2 -1
View File
@@ -1,8 +1,9 @@
UNRELEASED
* dropped: support for Red Hat Enterprise Linux and its derivatives has been dropped; removed the RPM spec file, and will no longer build binaries
* fix: correction to `pv_in_foreground()` to behave as its comment block says it should, when not on a terminal - corrects [GH#19 "No output in Arch Linux initcpio after 1.6.6"](https://github.com/a-j-wood/pv/issues/19), [GH#55 "pv Stopped Working in the Background"](https://github.com/a-j-wood/pv/issues/55) (pull request [#64](https://github.com/a-j-wood/pv/pull/64) supplied by [Michael Weiß](https://github.com/quitschbo))
* feature: the "`--watchfd`" option will now show relative filenames, if they are under the current directory (pull request [#66](https://github.com/a-j-wood/pv/pull/66) supplied by [ikasty](https://github.com/ikasty))
* feature: the "`--size`" option now accepts "`@filename`" to use the size of another file (pull request [#57](https://github.com/a-j-wood/pv/pull/57) supplied by [Dave Beckett](https://github.com/dajobe))
* feature: the "`--watchfd`" option is now available on OS X (pull request [#60](https://github.com/a-j-wood/pv/pull/60) supplied by [christoph-zededa](https://github.com/christoph-zededa))
* feature: the "`--watchfd`" option will now show relative filenames, if they are under the current directory (pull request [#66](https://github.com/a-j-wood/pv/pull/66) supplied by [ikasty](https://github.com/ikasty))
* docs: moved all open issues into GitHub and updated the TODO list
* docs: renamed README to README.md and altered it to Markdown format
* docs: moved contributors from the README to docs/ACKNOWLEDGEMENTS.md
+12 -1
View File
@@ -243,7 +243,18 @@ etc can be used as with
.BR -L .
.TP
.B ""
Has no effect if used with
If
.B SIZE
starts with
.BR "@" ,
the size of file whose name follows the
.B @
will be used.
.TP
.B ""
Note that
.B \-\-size
has no effect if used with
.B -d PID
to watch all file descriptors of a process, but will work with
.BR "-d PID:FD" .
+27 -1
View File
@@ -8,11 +8,13 @@
#include "options.h"
#include "library/getopt.h"
#include "pv.h"
#include "pv-internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -138,6 +140,9 @@ opts_t opts_parse(int argc, char **argv)
*/
switch (c) {
case 's':
/* "-s @" is valid, so allow it. */
if ('@' == *optarg)
break;
case 'A':
case 'w':
case 'H':
@@ -257,7 +262,28 @@ opts_t opts_parse(int argc, char **argv)
opts->delay_start = pv_getnum_d(optarg);
break;
case 's':
opts->size = pv_getnum_ull(optarg);
/* Permit "@<filename>" as well as just a number. */
if ('@' == *optarg) {
const char *size_file = 1 + optarg;
struct stat64 sb;
int rc;
rc = 0;
memset(&sb, 0, sizeof(sb));
rc = stat64(size_file, &sb);
if (0 == rc) {
opts->size = sb.st_size;
} else {
fprintf(stderr, "%s: %s %s: %s\n",
opts->program_name,
_("failed to stat file"),
size_file, strerror(errno));
opts_free(opts);
return NULL;
}
} else {
opts->size = pv_getnum_ull(optarg);
}
break;
case 'l':
opts->linemode = true;