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