File: open.c

package info (click to toggle)
es 0.90beta1-6
  • links: PTS
  • area: main
  • in suites: potato, slink
  • size: 728 kB
  • ctags: 981
  • sloc: ansic: 8,081; sh: 1,503; makefile: 142; yacc: 109
file content (30 lines) | stat: -rw-r--r-- 779 bytes parent folder | download | duplicates (5)
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
26
27
28
29
30
/* open.c -- to insulate <fcntl.h> from the rest of es ($Revision: 1.1.1.1 $) */

#define	REQUIRE_FCNTL	1

#include "es.h"

#if NeXT
extern int open(const char *, int, ...);
#endif

/*
 * Opens a file with the necessary flags.  Assumes the following order:
 *	typedef enum {
 *		oOpen, oCreate, oAppend, oReadCreate, oReadTrunc oReadAppend
 *	} OpenKind;
 */

static int mode_masks[] = {
	O_RDONLY,			/* rOpen */
	O_WRONLY | O_CREAT | O_TRUNC,	/* rCreate */
	O_WRONLY | O_CREAT | O_APPEND,	/* rAppend */
	O_RDWR   | O_CREAT,		/* oReadWrite */
	O_RDWR   | O_CREAT | O_TRUNC,	/* oReadCreate */
	O_RDWR   | O_CREAT | O_APPEND,	/* oReadAppend */
};

extern int eopen(char *name, OpenKind k) {
	assert((unsigned) k < arraysize(mode_masks));
	return open(name, mode_masks[k], 0666);
}