From e11c7df86144bed383ac6bbeaecc3017d18b37db Mon Sep 17 00:00:00 2001 From: Toby Goodwin Date: Mon, 11 Jan 1999 10:55:18 +0000 Subject: beta: rc-1.5b4 --- open.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'open.c') 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 from the rest of rc. */ -#include #include "rc.h" +#include /* 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; +} -- cgit v1.2.3