summaryrefslogtreecommitdiff
path: root/src/shuf.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2013-03-27 11:06:00 +0000
committerPádraig Brady <P@draigBrady.com>2013-04-04 02:55:55 +0100
commitf7867e73caac82349e5623d04e46aaf784778644 (patch)
tree6a08f079b9829745b107d3972e762138dacc2ec5 /src/shuf.c
parent34023817cb0225b50779a546a58e057e5e920d2c (diff)
downloadcoreutils-f7867e73caac82349e5623d04e46aaf784778644.tar.xz
shuf: exit without reading if would never output
* src/shuf.c (main): If -n0 specified then no data would ever be output, so exit without reading input. * tests/misc/shuf.sh: Augment the related test with this case.
Diffstat (limited to 'src/shuf.c')
-rw-r--r--src/shuf.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/shuf.c b/src/shuf.c
index bbf3a86c2..0fabb0bfe 100644
--- a/src/shuf.c
+++ b/src/shuf.c
@@ -463,7 +463,8 @@ main (int argc, char **argv)
break;
case 1:
- if (! (STREQ (operand[0], "-") || freopen (operand[0], "r", stdin)))
+ if (! (STREQ (operand[0], "-") || ! head_lines
+ || freopen (operand[0], "r", stdin)))
error (EXIT_FAILURE, errno, "%s", operand[0]);
break;
@@ -474,7 +475,8 @@ main (int argc, char **argv)
fadvise (stdin, FADVISE_SEQUENTIAL);
- if (head_lines != SIZE_MAX && input_size () > RESERVOIR_MIN_INPUT)
+ if (head_lines != SIZE_MAX && (! head_lines
+ || input_size () > RESERVOIR_MIN_INPUT))
{
use_reservoir_sampling = true;
n_lines = SIZE_MAX; /* unknown number of input lines, for now. */