summaryrefslogtreecommitdiffstats
path: root/fdmisc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fdmisc.c')
-rw-r--r--fdmisc.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/fdmisc.c b/fdmisc.c
index 8c8b91e..eb7a6fc 100644
--- a/fdmisc.c
+++ b/fdmisc.c
@@ -36,25 +36,43 @@
#include "memdbg.h"
/* Set a file descriptor to non-blocking */
-void
-set_nonblock (int fd)
+bool
+set_nonblock_action (int fd)
{
#ifdef WIN32
u_long arg = 1;
if (ioctlsocket (fd, FIONBIO, &arg))
- msg (M_SOCKERR, "Set socket to non-blocking mode failed");
+ return false;
#else
if (fcntl (fd, F_SETFL, O_NONBLOCK) < 0)
- msg (M_ERR, "Set file descriptor to non-blocking mode failed");
+ return false;
#endif
+ return true;
}
/* Set a file descriptor to not be passed across execs */
-void
-set_cloexec (int fd)
+bool
+set_cloexec_action (int fd)
{
#ifndef WIN32
if (fcntl (fd, F_SETFD, FD_CLOEXEC) < 0)
- msg (M_ERR, "Set FD_CLOEXEC flag on file descriptor failed");
+ return false;
#endif
+ return true;
+}
+
+/* Set a file descriptor to non-blocking */
+void
+set_nonblock (int fd)
+{
+ if (!set_nonblock_action (fd))
+ msg (M_SOCKERR, "Set socket to non-blocking mode failed");
+}
+
+/* Set a file descriptor to not be passed across execs */
+void
+set_cloexec (int fd)
+{
+ if (!set_cloexec_action (fd))
+ msg (M_ERR, "Set FD_CLOEXEC flag on file descriptor failed");
}