diff options
| author | Toby Goodwin <tjg@star.le.ac.uk> | 1999-01-11 10:55:18 +0000 |
|---|---|---|
| committer | Toby Goodwin <toby@paccrat.org> | 2015-05-16 21:22:09 +0100 |
| commit | e11c7df86144bed383ac6bbeaecc3017d18b37db (patch) | |
| tree | 6fad44921723eab2f2eb1c76b7214b4e79b818f3 /open.c | |
| parent | 671e1e2d1599aa8c5f1010b3fe75c151c56a7403 (diff) | |
beta: rc-1.5b4
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; +} |