diff options
Diffstat (limited to 'src/shuf.c')
| -rw-r--r-- | src/shuf.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/shuf.c b/src/shuf.c index 2338cdb78..436f327e1 100644 --- a/src/shuf.c +++ b/src/shuf.c @@ -22,8 +22,6 @@ #include <sys/types.h> #include "system.h" -#include "die.h" -#include "error.h" #include "fadvise.h" #include "getopt.h" #include "linebuffer.h" @@ -222,14 +220,14 @@ read_input_reservoir_sampling (FILE *in, char eolbyte, size_t k, while (readlinebuffer_delim (line, in, eolbyte) != nullptr && n_lines++); if (! n_lines) - die (EXIT_FAILURE, EOVERFLOW, _("too many input lines")); + error (EXIT_FAILURE, EOVERFLOW, _("too many input lines")); freebuffer (&dummy); } /* no more input lines, or an input error. */ if (ferror (in)) - die (EXIT_FAILURE, errno, _("read error")); + error (EXIT_FAILURE, errno, _("read error")); *out_rsrv = rsrv; return MIN (k, n_lines); @@ -275,7 +273,7 @@ read_input (FILE *in, char eolbyte, char ***pline) avoiding the reservoir CPU overhead when reading < RESERVOIR_MIN_INPUT from a pipe, and allow us to dispense with the input_size() function. */ if (!(buf = fread_file (in, 0, &used))) - die (EXIT_FAILURE, errno, _("read error")); + error (EXIT_FAILURE, errno, _("read error")); if (used && buf[used - 1] != eolbyte) buf[used++] = eolbyte; @@ -411,7 +409,7 @@ main (int argc, char **argv) case 'i': { if (input_range) - die (EXIT_FAILURE, 0, _("multiple -i options specified")); + error (EXIT_FAILURE, 0, _("multiple -i options specified")); input_range = true; uintmax_t u; @@ -439,8 +437,8 @@ main (int argc, char **argv) n_lines = hi_input - lo_input + 1; if (err != LONGINT_OK || (lo_input <= hi_input) == (n_lines == 0)) - die (EXIT_FAILURE, err == LONGINT_OVERFLOW ? EOVERFLOW : 0, - "%s: %s", _("invalid input range"), quote (optarg)); + error (EXIT_FAILURE, err == LONGINT_OVERFLOW ? EOVERFLOW : 0, + "%s: %s", _("invalid input range"), quote (optarg)); } break; @@ -452,20 +450,20 @@ main (int argc, char **argv) if (e == LONGINT_OK) head_lines = MIN (head_lines, argval); else if (e != LONGINT_OVERFLOW) - die (EXIT_FAILURE, 0, _("invalid line count: %s"), - quote (optarg)); + error (EXIT_FAILURE, 0, _("invalid line count: %s"), + quote (optarg)); } break; case 'o': if (outfile && !STREQ (outfile, optarg)) - die (EXIT_FAILURE, 0, _("multiple output files specified")); + error (EXIT_FAILURE, 0, _("multiple output files specified")); outfile = optarg; break; case RANDOM_SOURCE_OPTION: if (random_source && !STREQ (random_source, optarg)) - die (EXIT_FAILURE, 0, _("multiple random sources specified")); + error (EXIT_FAILURE, 0, _("multiple random sources specified")); random_source = optarg; break; @@ -521,7 +519,7 @@ main (int argc, char **argv) if (n_operands == 1 && ! (STREQ (operand[0], "-") || freopen (operand[0], "r", stdin))) - die (EXIT_FAILURE, errno, "%s", quotef (operand[0])); + error (EXIT_FAILURE, errno, "%s", quotef (operand[0])); fadvise (stdin, FADVISE_SEQUENTIAL); @@ -547,8 +545,8 @@ main (int argc, char **argv) ? SIZE_MAX : randperm_bound (ahead_lines, n_lines))); if (! randint_source) - die (EXIT_FAILURE, errno, "%s", - quotef (random_source ? random_source : "getrandom")); + error (EXIT_FAILURE, errno, "%s", + quotef (random_source ? random_source : "getrandom")); if (use_reservoir_sampling) { @@ -563,13 +561,13 @@ main (int argc, char **argv) doesn't have to worry about opening something other than stdin. */ if (! (head_lines == 0 || echo || input_range || fclose (stdin) == 0)) - die (EXIT_FAILURE, errno, _("read error")); + error (EXIT_FAILURE, errno, _("read error")); if (!repeat) permutation = randperm_new (randint_source, ahead_lines, n_lines); if (outfile && ! freopen (outfile, "w", stdout)) - die (EXIT_FAILURE, errno, "%s", quotef (outfile)); + error (EXIT_FAILURE, errno, "%s", quotef (outfile)); /* Generate output according to requested method */ if (repeat) @@ -579,7 +577,7 @@ main (int argc, char **argv) else { if (n_lines == 0) - die (EXIT_FAILURE, 0, _("no lines to repeat")); + error (EXIT_FAILURE, 0, _("no lines to repeat")); if (input_range) i = write_random_numbers (randint_source, ahead_lines, lo_input, hi_input, eolbyte); @@ -599,7 +597,7 @@ main (int argc, char **argv) } if (i != 0) - die (EXIT_FAILURE, errno, _("write error")); + error (EXIT_FAILURE, errno, _("write error")); main_exit (EXIT_SUCCESS); } |
