[Toybox] [PATCH] grep: add --line-buffered and fix regular buffering.

enh enh at google.com
Sun Feb 24 14:27:57 PST 2019


This is slightly more involved than just calling setlinebuf(3) because
the code was already implicitly flushing more than once per line thanks
to all the calls to the 'x' wrappers around stdio.

I've un-'x'ed putsl and putsn, given that the only caller doesn't want
to flush that often, but I left them in lib/ for now.

As usual I haven't added a bogus short option to correspond to
--line-buffered because I fear that one day (when it's many years
of existing practice too late to fix either side) we'll end up with
a collision.

Tested by looking at `strace -e write` output when running
`grep fpu_ /proc/cpuinfo > /dev/null` with and without --line-buffered
(the redirection is necessary because stdout is line buffered by default
if it's a terminal).
---
 lib/lib.c         | 17 +++++++++++++++++
 lib/lib.h         |  4 ++--
 lib/xwrap.c       | 19 -------------------
 toys/posix/grep.c | 31 ++++++++++++++++---------------
 4 files changed, 35 insertions(+), 36 deletions(-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-grep-add-line-buffered-and-fix-regular-buffering.patch
Type: text/x-patch
Size: 6376 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20190224/7a962a83/attachment-0002.bin>


More information about the Toybox mailing list