-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen.c
More file actions
32 lines (28 loc) · 1.04 KB
/
open.c
File metadata and controls
32 lines (28 loc) · 1.04 KB
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
31
32
/* open.c -- to insulate <fcntl.h> from the rest of es ($Revision: 1.1.1.1 $) */
#include "es.h"
/*
* 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, /* oOpen */
O_WRONLY | O_CREAT | O_TRUNC, /* oCreate */
O_WRONLY | O_CREAT | O_APPEND, /* oAppend */
O_RDWR | O_CREAT, /* oReadWrite */
O_RDWR | O_CREAT | O_TRUNC, /* oReadCreate */
O_RDWR | O_CREAT | O_APPEND, /* oReadAppend */
O_RDONLY | O_CLOEXEC, /* ceOpen */
O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, /* ceCreate */
O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, /* ceAppend */
O_RDWR | O_CREAT | O_CLOEXEC, /* ceReadWrite */
O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, /* ceReadCreate */
O_RDWR | O_CREAT | O_APPEND | O_CLOEXEC, /* ceReadAppend */
};
extern int
eopen(char *name, OpenKind k)
{
assert((unsigned)k < arraysize(mode_masks));
return open(name, mode_masks[k], 0666);
}