diff options
| author | Byron Rakitzis <byron@archone.tamu.edu> | 1992-05-27 00:00:01 +0100 |
|---|---|---|
| committer | Toby Goodwin <toby@paccrat.org> | 2015-05-16 21:22:04 +0100 |
| commit | 6bb38f6a01dbf4bbd584e038ceace0a00faa27bb (patch) | |
| tree | 589705b2492ce4681760846d9ca45600f0af298d /open.c | |
release: rc-1.4
Diffstat (limited to 'open.c')
| -rw-r--r-- | open.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -0,0 +1,29 @@ +/* open.c: to insulate <fcntl.h> from the rest of rc. */ + +#include <fcntl.h> +#include "rc.h" + +/* prototype for open() follows. comment out if necessary */ + +/*extern int open(const char *, int,...);*/ + +/* + Opens a file with the necessary flags. Assumes the following + declaration for redirtype: + + enum redirtype { + rFrom, rCreate, rAppend, rHeredoc, rHerestring + }; +*/ + +static const int mode_masks[] = { + /* rFrom */ O_RDONLY, + /* rCreate */ O_TRUNC | O_CREAT | O_WRONLY, + /* rAppend */ O_APPEND | O_CREAT | O_WRONLY +}; + +extern int rc_open(const char *name, redirtype m) { + if ((unsigned) m >= arraysize(mode_masks)) + panic("bad mode passed to rc_open"); + return open(name, mode_masks[m], 0666); +} |