Applied patch from Dave Beckett to support "@filename" as a "--size" argument.
This commit is contained in:
+27
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user