summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-07-27 15:14:37 +0200
committerJim Meyering <meyering@redhat.com>2008-07-27 15:25:27 +0200
commitbee58d8a0400b0303c6dce3873fdf3482de0c110 (patch)
treedbef2d9ac7afe3398a2d2ca070bc891c368a82a4 /src
parente535754fdbe701e70f3ac9834b643a9272dc1d98 (diff)
downloadcoreutils-bee58d8a0400b0303c6dce3873fdf3482de0c110.tar.xz
shuf: honor --zero-terminated option even with --input-range=LO-HI
* src/shuf.c (write_permuted_output): Add EOLBYTE parameter and use it rather than hard-coding "\n". (main): Adjust sole caller. * tests/misc/shuf: Add a test to exercise this bug fix. * NEWS: Mention it.
Diffstat (limited to 'src')
-rw-r--r--src/shuf.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/shuf.c b/src/shuf.c
index ca5345b4b..5e07d6e49 100644
--- a/src/shuf.c
+++ b/src/shuf.c
@@ -214,7 +214,7 @@ read_input (FILE *in, char eolbyte, char ***pline)
static int
write_permuted_output (size_t n_lines, char * const *line, size_t lo_input,
- size_t const *permutation)
+ size_t const *permutation, char eolbyte)
{
size_t i;
@@ -230,7 +230,7 @@ write_permuted_output (size_t n_lines, char * const *line, size_t lo_input,
for (i = 0; i < n_lines; i++)
{
unsigned long int n = lo_input + permutation[i];
- if (printf ("%lu\n", n) < 0)
+ if (printf ("%lu%c", n, eolbyte) < 0)
return -1;
}
@@ -400,7 +400,8 @@ main (int argc, char **argv)
if (outfile && ! freopen (outfile, "w", stdout))
error (EXIT_FAILURE, errno, "%s", quotearg_colon (outfile));
- if (write_permuted_output (head_lines, line, lo_input, permutation) != 0)
+ if (write_permuted_output (head_lines, line, lo_input, permutation, eolbyte)
+ != 0)
error (EXIT_FAILURE, errno, _("write error"));
#ifdef lint