From 6bb38f6a01dbf4bbd584e038ceace0a00faa27bb Mon Sep 17 00:00:00 2001 From: Byron Rakitzis Date: Wed, 27 May 1992 00:00:01 +0100 Subject: release: rc-1.4 --- open.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 open.c (limited to 'open.c') diff --git a/open.c b/open.c new file mode 100644 index 0000000..7287e0e --- /dev/null +++ b/open.c @@ -0,0 +1,29 @@ +/* open.c: to insulate from the rest of rc. */ + +#include +#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); +} -- cgit v1.2.3