summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/xfuncs.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/xfuncs.c b/src/lib/xfuncs.c
index be02c56a..f451693a 100644
--- a/src/lib/xfuncs.c
+++ b/src/lib/xfuncs.c
@@ -26,12 +26,18 @@
/* Turn on nonblocking I/O on a fd */
int 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 0;
+ return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
int 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 0;
+ return fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
}
int close_on_exec_on(int fd)