aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-01-24 00:29:55 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-01-24 00:29:55 +0100
commite9a40e3b91f699c08053d7307bf50b0764811b8e (patch)
tree790f2cae8fbca16cfa2b5c1f5ed98d4c4afdf198
parentdc6cd12569e6ac3775b11f6285ccc1bb81b13af0 (diff)
downloadbusybox-w32-e9a40e3b91f699c08053d7307bf50b0764811b8e.tar.gz
busybox-w32-e9a40e3b91f699c08053d7307bf50b0764811b8e.tar.bz2
busybox-w32-e9a40e3b91f699c08053d7307bf50b0764811b8e.zip
libbb: make ndelay_no/off a bit more clever. +14 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h6
-rw-r--r--libbb/xfuncs.c18
2 files changed, 15 insertions, 9 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 55510316b..6e37b8d04 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;
348/* "abc/def/" -> "" and it never modifies 'path' */ 348/* "abc/def/" -> "" and it never modifies 'path' */
349extern char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC; 349extern char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC;
350 350
351int ndelay_on(int fd) FAST_FUNC; 351void ndelay_on(int fd) FAST_FUNC;
352int ndelay_off(int fd) FAST_FUNC; 352void ndelay_off(int fd) FAST_FUNC;
353int close_on_exec_on(int fd) FAST_FUNC; 353void close_on_exec_on(int fd) FAST_FUNC;
354void xdup2(int, int) FAST_FUNC; 354void xdup2(int, int) FAST_FUNC;
355void xmove_fd(int, int) FAST_FUNC; 355void xmove_fd(int, int) FAST_FUNC;
356 356
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 @@
25#include "libbb.h" 25#include "libbb.h"
26 26
27/* Turn on nonblocking I/O on a fd */ 27/* Turn on nonblocking I/O on a fd */
28int FAST_FUNC ndelay_on(int fd) 28void FAST_FUNC ndelay_on(int fd)
29{ 29{
30 return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); 30 int flags = fcntl(fd, F_GETFL);
31 if (flags & O_NONBLOCK)
32 return;
33 fcntl(fd, F_SETFL, flags | O_NONBLOCK);
31} 34}
32 35
33int FAST_FUNC ndelay_off(int fd) 36void FAST_FUNC ndelay_off(int fd)
34{ 37{
35 return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK); 38 int flags = fcntl(fd, F_GETFL);
39 if (!(flags & O_NONBLOCK))
40 return;
41 fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
36} 42}
37 43
38int FAST_FUNC close_on_exec_on(int fd) 44void FAST_FUNC close_on_exec_on(int fd)
39{ 45{
40 return fcntl(fd, F_SETFD, FD_CLOEXEC); 46 fcntl(fd, F_SETFD, FD_CLOEXEC);
41} 47}
42 48
43char* FAST_FUNC strncpy_IFNAMSIZ(char *dst, const char *src) 49char* FAST_FUNC strncpy_IFNAMSIZ(char *dst, const char *src)