aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-14 16:18:16 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-14 16:18:16 +0200
commit63214a68f1b553e09ae18956cd7e4ec9543535c5 (patch)
tree51654d9dfed26a578cf6090193c2cb0333740c8a
parent5f7904b6d11355a2010ebd10960d6a5d469301cc (diff)
downloadbusybox-63214a68f1b553e09ae18956cd7e4ec9543535c5.tar.gz
libbb/dump: allow skipping over stdin too
function old new delta next 294 265 -29 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/dump.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/libbb/dump.c b/libbb/dump.c
index bc0c1ec80..189277297 100644
--- a/libbb/dump.c
+++ b/libbb/dump.c
@@ -311,20 +311,18 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs)
}
}
-static void do_skip(priv_dumper_t *dumper, const char *fname, int statok)
+static void do_skip(priv_dumper_t *dumper, const char *fname)
{
struct stat sbuf;
- if (statok) {
- xfstat(STDIN_FILENO, &sbuf, fname);
- if (!(S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode) || S_ISFIFO(sbuf.st_mode))
- && dumper->pub.dump_skip >= sbuf.st_size
- ) {
- /* If st_size is valid and pub.dump_skip >= st_size */
- dumper->pub.dump_skip -= sbuf.st_size;
- dumper->address += sbuf.st_size;
- return;
- }
+ xfstat(STDIN_FILENO, &sbuf, fname);
+ if (S_ISREG(sbuf.st_mode)
+ && dumper->pub.dump_skip >= sbuf.st_size
+ ) {
+ /* If st_size is valid and pub.dump_skip >= st_size */
+ dumper->pub.dump_skip -= sbuf.st_size;
+ dumper->address += sbuf.st_size;
+ return;
}
if (fseeko(stdin, dumper->pub.dump_skip, SEEK_SET)) {
bb_simple_perror_msg_and_die(fname);
@@ -336,14 +334,11 @@ static void do_skip(priv_dumper_t *dumper, const char *fname, int statok)
static NOINLINE int next(priv_dumper_t *dumper)
{
- int statok;
-
for (;;) {
- char *fname = *dumper->argv;
+ const char *fname = *dumper->argv;
if (fname) {
dumper->argv++;
- dumper->next__done = statok = 1;
if (!freopen(fname, "r", stdin)) {
bb_simple_perror_msg(fname);
dumper->exitval = 1;
@@ -352,13 +347,11 @@ static NOINLINE int next(priv_dumper_t *dumper)
} else {
if (dumper->next__done)
return 0; /* no next file */
- dumper->next__done = 1;
-//why stat of stdin is specially prohibited?
- statok = 0;
}
+ dumper->next__done = 1;
if (dumper->pub.dump_skip)
- do_skip(dumper, statok ? fname : "stdin", statok);
- if (!dumper->pub.dump_skip)
+ do_skip(dumper, fname ? fname : "stdin");
+ if (dumper->pub.dump_skip == 0)
return 1;
}
/* NOTREACHED */