summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixCompat.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/tclUnixCompat.c')
-rw-r--r--unix/tclUnixCompat.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/unix/tclUnixCompat.c b/unix/tclUnixCompat.c
index 9436ae7..ba07c8c 100644
--- a/unix/tclUnixCompat.c
+++ b/unix/tclUnixCompat.c
@@ -6,7 +6,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixCompat.c,v 1.9.2.3 2007/11/16 07:20:58 dgp Exp $
+ * RCS: @(#) $Id: tclUnixCompat.c,v 1.9.2.4 2008/03/07 22:05:10 dgp Exp $
*
*/
@@ -16,6 +16,50 @@
#include <errno.h>
#include <string.h>
+/* See also: SC_BLOCKING_STYLE in unix/tcl.m4
+ */
+#ifdef USE_FIONBIO
+# ifdef HAVE_SYS_FILIO_H
+# include <sys/filio.h> /* For FIONBIO. */
+# endif
+# ifdef HAVE_SYS_IOCTL_H
+# include <sys/ioctl.h>
+# endif
+#endif /* USE_FIONBIO */
+
+/*
+ *---------------------------------------------------------------------------
+ *
+ * TclUnixSetBlockingMode --
+ *
+ * Set the blocking mode of a file descriptor.
+ *
+ * Results:
+ *
+ * 0 on success, -1 (with errno set) on error.
+ *
+ *---------------------------------------------------------------------------
+ */
+int
+TclUnixSetBlockingMode(
+ int fd, /* File descriptor */
+ int mode) /* TCL_MODE_BLOCKING or TCL_MODE_NONBLOCKING */
+{
+#ifndef USE_FIONBIO
+ int flags = fcntl(fd, F_GETFL);
+
+ if (mode == TCL_MODE_BLOCKING) {
+ flags &= ~O_NONBLOCK;
+ } else {
+ flags |= O_NONBLOCK;
+ }
+ return fcntl(fd, F_SETFL, flags);
+#else /* USE_FIONBIO */
+ int state = (mode == TCL_MODE_NONBLOCKING);
+ return ioctl(fd, FIONBIO, &state);
+#endif /* !USE_FIONBIO */
+}
+
/*
* Used to pad structures at size'd boundaries
*