file types, a warning is issued for source directories with duplicate names,
or with -H the directory is copied again using the symlink name.
+ factor avoids writing partial lines, thus supporting parallel operation.
+ [the bug dates back to the initial implementation]
+
head, od, split, tac, tail, and wc no longer mishandle input from files in
/proc and /sys file systems that report somewhat-incorrect file sizes.
return err;
}
+static size_t n_out; /* How much data we've written to stdout. */
+
static void
print_uintmaxes (uintmax_t t1, uintmax_t t0)
{
uintmax_t q, r;
if (t1 == 0)
- printf ("%"PRIuMAX, t0);
+ n_out += printf ("%"PRIuMAX, t0);
else
{
/* Use very plain code here since it seems hard to write fast code
r = t1 % 1000000000;
udiv_qrnnd (t0, r, r, t0, 1000000000);
print_uintmaxes (q, t0);
- printf ("%09u", (unsigned int) r);
+ n_out += printf ("%09u", (unsigned int) r);
}
}
print_uintmaxes (t1, t0);
putchar (':');
+ n_out++;
factor (t1, t0, &factors);
{
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
putchar (' ');
- fputs (umaxtostr (factors.p[j], buf), stdout);
+ char *umaxstr = umaxtostr (factors.p[j], buf);
+ fputs (umaxstr, stdout);
+ n_out += strlen (umaxstr) + 1;
}
if (factors.plarge[1])
{
putchar (' ');
+ n_out++;
print_uintmaxes (factors.plarge[1], factors.plarge[0]);
}
putchar ('\n');
+ n_out++;
+
+ /* Assume the stdout buffer is > this value.
+ Flush here to avoid partial lines being output.
+ Flushing every line has too much overhead.
+ TODO: Buffer internally and avoid stdio. */
+ if (n_out >= 512)
+ {
+ fflush (stdout);
+ n_out = 0;
+ }
}
/* Emit the factors of the indicated number. If we have the option of using
mp_factor_clear (&factors);
mpz_clear (t);
putchar ('\n');
+ fflush (stdout);
return true;
#else
error (0, 0, _("%s is too large"), quote (input));
tests/misc/expand.pl \
tests/misc/expr.pl \
tests/misc/factor.pl \
+ tests/misc/factor-parallel.sh \
tests/misc/false-status.sh \
tests/misc/fold.pl \
tests/misc/groups-dash.sh \
--- /dev/null
+#!/bin/sh
+# Test for complete lines on output
+
+# Copyright (C) 2015 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ factor
+
+
+odd() { LC_ALL=C sed '/[24680]$/d'; }
+primes() { LC_ALL=C sed 's/.*: //; / /d'; }
+
+# Before v8.24 the number reported here would vary
+# Note -u not supplied to split, increased batching of quickly processed items.
+# As processing cost increases it becomes advantageous to use -u to keep
+# the factor processes supplied with data.
+nprimes=$(seq 1e6 | odd | split -nr/4 --filter='factor' | primes | wc -l)
+
+test "$nprimes" = '78498' || fail=1
+
+Exit $fail