summaryrefslogtreecommitdiff
path: root/open.c
diff options
context:
space:
mode:
authorByron Rakitzis <byron@archone.tamu.edu>1992-05-27 00:00:01 +0100
committerToby Goodwin <toby@paccrat.org>2015-05-16 21:22:04 +0100
commit6bb38f6a01dbf4bbd584e038ceace0a00faa27bb (patch)
tree589705b2492ce4681760846d9ca45600f0af298d /open.c
release: rc-1.4
Diffstat (limited to 'open.c')
-rw-r--r--open.c29
1 files changed, 29 insertions, 0 deletions
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 <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);
+}