From d6e7672545c717497490c0b0f54f64594f374f9d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 22 Sep 2014 21:14:02 +0200 Subject: less: move "retry-on-EAGAIN" logic closer to read ops This makes "G" (goto end of input) command work as well as /search_for_nonexistent_string: both will read to EOF now even from somewhat slow input (such as kernel's "git log"). function old new delta ndelay_on 35 43 +8 ndelay_off 35 43 +8 read_lines 695 691 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-4) Total: 12 bytes Signed-off-by: Denys Vlasenko --- libbb/xfuncs.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'libbb') diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 23f2751..f25ce94 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -25,20 +25,22 @@ #include "libbb.h" /* Turn on nonblocking I/O on a fd */ -void FAST_FUNC ndelay_on(int fd) +int FAST_FUNC ndelay_on(int fd) { int flags = fcntl(fd, F_GETFL); if (flags & O_NONBLOCK) - return; + return flags; fcntl(fd, F_SETFL, flags | O_NONBLOCK); + return flags; } -void FAST_FUNC ndelay_off(int fd) +int FAST_FUNC ndelay_off(int fd) { int flags = fcntl(fd, F_GETFL); if (!(flags & O_NONBLOCK)) - return; + return flags; fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); + return flags; } void FAST_FUNC close_on_exec_on(int fd) -- cgit v1.1