File: open.c

package info (click to toggle)
rc 1.5b2-0.1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 540 kB
  • ctags: 756
  • sloc: ansic: 5,474; sh: 231; makefile: 138; yacc: 127
file content (25 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* open.c: to insulate <fcntl.h> from the rest of rc. */

#include <fcntl.h>
#include "rc.h"

/*
   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);
}