1/*
2 * Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _FCNTL_H
6#define _FCNTL_H
7
8
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <unistd.h>
12
13
14/* commands that can be passed to fcntl() */
15#define	F_DUPFD			0x0001		/* duplicate fd */
16#define	F_GETFD			0x0002		/* get fd flags */
17#define	F_SETFD			0x0004		/* set fd flags */
18#define	F_GETFL			0x0008		/* get file status flags and access mode */
19#define	F_SETFL			0x0010		/* set file status flags */
20#define F_GETLK         0x0020		/* get locking information */
21#define F_SETLK         0x0080		/* set locking information */
22#define F_SETLKW        0x0100		/* as above, but waits if blocked */
23#define F_DUPFD_CLOEXEC 0x0200		/* duplicate fd with close on exec set */
24
25/* advisory locking types */
26#define F_RDLCK         0x0040		/* read or shared lock */
27#define F_UNLCK         0x0200		/* unlock */
28#define F_WRLCK         0x0400		/* write or exclusive lock */
29
30/* file descriptor flags for fcntl() */
31#define FD_CLOEXEC		1			/* close on exec */
32
33/* file access modes for open() */
34#define O_RDONLY		0x0000		/* read only */
35#define O_WRONLY		0x0001		/* write only */
36#define O_RDWR			0x0002		/* read and write */
37#define O_ACCMODE   	0x0003		/* mask to get the access modes above */
38#define O_RWMASK		O_ACCMODE
39
40/* flags for open() */
41#define	O_EXCL			0x0100		/* exclusive creat */
42#define O_CREAT			0x0200		/* create and open file */
43#define O_TRUNC			0x0400		/* open with truncation */
44#define O_NOCTTY		0x1000		/* don't make tty the controlling tty */
45#define	O_NOTRAVERSE	0x2000		/* do not traverse leaf link */
46
47/* flags for open() and fcntl() */
48#define O_CLOEXEC		0x00000040	/* close on exec */
49#define	O_NONBLOCK		0x00000080	/* non blocking io */
50#define	O_NDELAY		O_NONBLOCK
51#define O_APPEND		0x00000800	/* to end of file */
52#define O_SYNC			0x00010000	/* write synchronized I/O file integrity */
53#define O_RSYNC			0x00020000	/* read synchronized I/O file integrity */
54#define O_DSYNC			0x00040000	/* write synchronized I/O data integrity */
55#define O_NOFOLLOW		0x00080000	/* fail on symlinks */
56#define O_DIRECT		0x00100000	/* do not use the file system cache if */
57									/* possible */
58#define O_NOCACHE		O_DIRECT
59#define O_DIRECTORY		0x00200000	/* fail if not a directory */
60
61/* flags for the *at() functions */
62#define AT_FDCWD		(-100)		/* CWD FD for the *at() functions */
63
64#define AT_SYMLINK_NOFOLLOW	0x01	/* fstatat(), fchmodat(), fchownat(),
65										utimensat() */
66#define AT_SYMLINK_FOLLOW	0x02	/* linkat() */
67#define AT_REMOVEDIR		0x04	/* unlinkat() */
68#define AT_EACCESS			0x08	/* faccessat() */
69
70/* file advisory information, unused by Haiku */
71#define POSIX_FADV_NORMAL		0	/* no advice */
72#define POSIX_FADV_SEQUENTIAL	1	/* expect sequential access */
73#define POSIX_FADV_RANDOM		2	/* expect access in a random order */
74#define POSIX_FADV_WILLNEED		3	/* expect access in the near future */
75#define POSIX_FADV_DONTNEED		4	/* expect no access in the near future */
76#define POSIX_FADV_NOREUSE		5	/* expect access only once */
77
78/* advisory file locking */
79
80struct flock {
81	short	l_type;
82	short	l_whence;
83	off_t	l_start;
84	off_t	l_len;
85	pid_t	l_pid;
86};
87
88
89#ifdef __cplusplus
90extern "C" {
91#endif
92
93extern int	creat(const char *path, mode_t mode);
94extern int	open(const char *path, int openMode, ...);
95	/* the third argument is the permissions of the created file when O_CREAT
96	   is passed in oflags */
97extern int	openat(int fd, const char *path, int openMode, ...);
98
99extern int	fcntl(int fd, int op, ...);
100
101extern int	posix_fadvise(int fd, off_t offset, off_t len, int advice);
102extern int	posix_fallocate(int fd, off_t offset, off_t len);
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif	/* _FCNTL_H */
109