]> git.ipfire.org Git - thirdparty/coreutils.git/commit
factor: ensure atomic output through pipes
authorPádraig Brady <P@draigBrady.com>
Tue, 30 Jun 2015 05:58:57 +0000 (06:58 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 1 Jul 2015 11:27:29 +0000 (12:27 +0100)
commitf2db30e676c2f124a318b2313946b450fb9de79f
tree7f60e8864af844e2181d08ad96286d9e035c6ad9
parente1358a7dd9817fd36166aaaa06cb10cfdd4c3ea7
factor: ensure atomic output through pipes

The new tests/misc/factor-parallel.sh test was
seen to fail on FreeBSD (derived) systems, which was
due to split(1) --filter reading partial lines
through pipes, as factor(1) was writing a little
over PIPE_BUF each time.

* src/factor.c (lbuf): A new structure to internally buffer lines.
(lbuf_alloc): A new function to allocate enough at program start.
(lbuf_putint): A new function to buffer a uintmax_t.
(lbuf_flush): A new function to write directly to standard output.
(lbuf_putc): A new function to buffer a character and if enough
lines are buffered, then output complete lines <= PIPE_BUF,
and continue to buffer the rest.
(main): Call the internal buffer allocator, and register
the final flush from the internal buffer at program exit.
src/factor.c