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;
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. */
timeout 10 shuf -i1-$SIZE_MAX -n2 >/dev/null ||
{ fail=1; echo "couldn't get a small subset" >&2; }
+# Ensure shuf -n0 doesn't read any input or open specified files
+touch unreadable || framework_failure_
+chmod 0 unreadable || framework_failure_
+shuf -n0 unreadable || fail=1
+shuf -n1 unreadable && fail=1
+
Exit $fail