[git commit master 1/1] libbb: make ndelay_no/off a bit more clever. +14 bytes

Denys Vlasenko vda.linux at googlemail.com
Sun Jan 23 23:29:55 UTC 2011


commit: http://git.busybox.net/busybox/commit/?id=e9a40e3b91f699c08053d7307bf50b0764811b8e
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 include/libbb.h |    6 +++---
 libbb/xfuncs.c  |   18 ++++++++++++------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/include/libbb.h b/include/libbb.h
index 5551031..6e37b8d 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -348,9 +348,9 @@ extern char *bb_get_last_path_component_strip(char *path) FAST_FUNC;
 /* "abc/def/" -> "" and it never modifies 'path' */
 extern char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC;
 
-int ndelay_on(int fd) FAST_FUNC;
-int ndelay_off(int fd) FAST_FUNC;
-int close_on_exec_on(int fd) FAST_FUNC;
+void ndelay_on(int fd) FAST_FUNC;
+void ndelay_off(int fd) FAST_FUNC;
+void close_on_exec_on(int fd) FAST_FUNC;
 void xdup2(int, int) FAST_FUNC;
 void xmove_fd(int, int) FAST_FUNC;
 
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index a02a504..23f2751 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)
-- 
1.7.3.4



More information about the busybox-cvs mailing list