From e9a40e3b91f699c08053d7307bf50b0764811b8e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 24 Jan 2011 00:29:55 +0100 Subject: libbb: make ndelay_no/off a bit more clever. +14 bytes Signed-off-by: Denys Vlasenko --- libbb/xfuncs.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'libbb/xfuncs.c') diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index a02a504b0..23f27516f 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -25,19 +25,25 @@ #include "libbb.h" /* Turn on nonblocking I/O on a fd */ -int FAST_FUNC ndelay_on(int fd) +void FAST_FUNC ndelay_on(int fd) { - return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); + int flags = fcntl(fd, F_GETFL); + if (flags & O_NONBLOCK) + return; + fcntl(fd, F_SETFL, flags | O_NONBLOCK); } -int FAST_FUNC ndelay_off(int fd) +void FAST_FUNC ndelay_off(int fd) { - return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK); + int flags = fcntl(fd, F_GETFL); + if (!(flags & O_NONBLOCK)) + return; + fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); } -int FAST_FUNC close_on_exec_on(int fd) +void FAST_FUNC close_on_exec_on(int fd) { - return fcntl(fd, F_SETFD, FD_CLOEXEC); + fcntl(fd, F_SETFD, FD_CLOEXEC); } char* FAST_FUNC strncpy_IFNAMSIZ(char *dst, const char *src) -- cgit v1.2.3