summaryrefslogtreecommitdiff
path: root/open.c
diff options
context:
space:
mode:
Diffstat (limited to 'open.c')
-rw-r--r--open.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/open.c b/open.c
index 2b6ee75..bac9f2c 100644
--- a/open.c
+++ b/open.c
@@ -1,7 +1,7 @@
/* open.c: to insulate <fcntl.h> from the rest of rc. */
-#include <fcntl.h>
#include "rc.h"
+#include <fcntl.h>
/*
Opens a file with the necessary flags. Assumes the following
@@ -23,3 +23,23 @@ extern int rc_open(const char *name, redirtype m) {
panic("bad mode passed to rc_open");
return open(name, mode_masks[m], 0666);
}
+
+/* make a file descriptor blocking. return value indicates whether
+the desciptor was previously set to non-blocking. */
+
+extern bool makeblocking(int fd) {
+ int flags;
+
+ if ((flags = fcntl(fd, F_GETFL)) == -1) {
+ uerror("fcntl");
+ rc_error(NULL);
+ }
+ if (! (flags & O_NONBLOCK))
+ return FALSE;
+ flags &= ~O_NONBLOCK;
+ if (fcntl(fd, F_SETFL, (long) flags) == -1) {
+ uerror("fcntl");
+ rc_error(NULL);
+ }
+ return TRUE;
+}