xref: /haiku/headers/posix/fcntl.h (revision 24159a0c7d6d6dcba9f2a0c1a7c08d2c8167f21b)
1 /*
2 ** Distributed under the terms of the Haiku License.
3 */
4 #ifndef _FCNTL_H
5 #define _FCNTL_H
6 
7 
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <unistd.h>
11 
12 
13 /* commands that can be passed to fcntl() */
14 #define	F_DUPFD			0x0001		/* duplicate fd */
15 #define	F_GETFD			0x0002		/* get fd flags */
16 #define	F_SETFD			0x0004		/* set fd flags */
17 #define	F_GETFL			0x0008		/* get file status flags and access mode */
18 #define	F_SETFL			0x0010		/* set file status flags */
19 #define F_GETLK         0x0020		/* get locking information */
20 #define F_RDLCK         0x0040		/* read or shared lock */
21 #define F_SETLK         0x0080		/* set locking information */
22 #define F_SETLKW        0x0100		/* as above, but waits if blocked */
23 #define F_UNLCK         0x0200		/* unlock */
24 #define F_WRLCK         0x0400		/* write or exclusive lock */
25 
26 /* file descriptor flags for fcntl() */
27 #define FD_CLOEXEC		1			/* close on exec */
28 
29 /* file access modes for open() */
30 #define O_RDONLY		0x0000		/* read only */
31 #define O_WRONLY		0x0001		/* write only */
32 #define O_RDWR			0x0002		/* read and write */
33 #define O_ACCMODE   	0x0003		/* mask to get the access modes above */
34 #define O_RWMASK		O_ACCMODE
35 
36 /* flags for open() */
37 #define	O_EXCL			0x0100		/* exclusive creat */
38 #define O_CREAT			0x0200		/* create and open file */
39 #define O_TRUNC			0x0400		/* open with truncation */
40 #define O_NOCTTY		0x1000		/* currently unsupported */
41 #define	O_NOTRAVERSE	0x2000		/* do not traverse leaf link */
42 
43 /* flags for open() and fcntl() */
44 #define O_CLOEXEC		0x00000040	/* close on exec */
45 #define	O_NONBLOCK		0x00000080	/* non blocking io */
46 #define O_APPEND		0x00000800	/* to end of file */
47 #define O_TEXT			0x00004000	/* CR-LF translation */
48 #define O_BINARY		0x00008000	/* no translation */
49 #define O_SYNC			0x00010000	/* write synchronized I/O file integrity */
50 #define O_RSYNC			0x00020000	/* read synchronized I/O file integrity */
51 #define O_DSYNC			0x00040000	/* write synchronized I/O data integrity */
52 
53 // ToDo: currently not implemented additions:
54 #define O_NOFOLLOW		0x00080000
55 	/* should we implement this? it's similar to O_NOTRAVERSE but will fail on symlinks */
56 #define O_NOCACHE		0x00100000	/* doesn't use the file system cache if possible */
57 #define O_DIRECT		O_NOCACHE
58 #define O_MOUNT			0x00200000	/* for file systems */
59 #define O_TEMPORARY		0x00400000	/* used to avoid writing temporary files to disk */
60 #define O_SHLOCK		0x01000000	/* obtain shared lock */
61 #define O_EXLOCK		0x02000000	/* obtain exclusive lock */
62 
63 
64 /* advisory file locking */
65 
66 struct flock {
67 	short	l_type;
68 	short	l_whence;
69 	off_t	l_start;
70 	off_t	l_len;
71 	pid_t	l_pid;
72 };
73 
74 #define	LOCK_SH		0x01	/* shared file lock */
75 #define	LOCK_EX		0x02	/* exclusive file lock */
76 #define	LOCK_NB		0x04	/* don't block when locking */
77 #define	LOCK_UN		0x08	/* unlock file */
78 
79 #define S_IREAD		0x0100  /* owner may read */
80 #define S_IWRITE	0x0080	/* owner may write */
81 
82 
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87 extern int	creat(const char *path, mode_t mode);
88 extern int	open(const char *pathname, int oflags, ...);
89 	/* the third argument is the permissions of the created file when O_CREAT
90 	   is passed in oflags */
91 
92 extern int	fcntl(int fd, int op, ...);
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif /* _FCNTL_H */
99