BSD 4_4_Lite1 development
[unix-history] / usr / src / contrib / rc-1.4 / open.c
CommitLineData
9d25673b
C
1/* open.c: to insulate <fcntl.h> from the rest of rc. */
2
3#include <fcntl.h>
4#include "rc.h"
5
6/* prototype for open() follows. comment out if necessary */
7
8/*extern int open(const char *, int,...);*/
9
10/*
11 Opens a file with the necessary flags. Assumes the following
12 declaration for redirtype:
13
14 enum redirtype {
15 rFrom, rCreate, rAppend, rHeredoc, rHerestring
16 };
17*/
18
19static const int mode_masks[] = {
20 /* rFrom */ O_RDONLY,
21 /* rCreate */ O_TRUNC | O_CREAT | O_WRONLY,
22 /* rAppend */ O_APPEND | O_CREAT | O_WRONLY
23};
24
25extern int rc_open(const char *name, redirtype m) {
26 if ((unsigned) m >= arraysize(mode_masks))
27 panic("bad mode passed to rc_open");
28 return open(name, mode_masks[m], 0666);
29}