diff options
Diffstat (limited to 'open.c')
| -rw-r--r-- | open.c | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -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; +} |