5 * This file includes the definitions for open and fcntl
6 * described by POSIX for <fcntl.h>.
8 #include <sys/featuretest.h>
10 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
12 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
15 * File status flags: these are used by open(2), fcntl(2).
16 * They are also used (indirectly) in the kernel file structure f_flags,
17 * which is a superset of the open/fcntl flags. Open flags and f_flags
18 * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
19 * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
22 #define O_RDONLY 0x00000000 /* open for reading only */
23 #define O_WRONLY 0x00000001 /* open for writing only */
24 #define O_RDWR 0x00000002 /* open for reading and writing */
25 #define O_ACCMODE 0x00000003 /* mask for above modes */
27 /* File status flags for open() and fcntl(). POSIX Table 6-5. */
28 #define O_APPEND 02000 /* set append mode */
29 #define O_NONBLOCK 04000 /* no delay */
30 #define O_REOPEN 010000 /* automatically re-open device after driver
35 #ifndef __minix /* NOT SUPPORTED! */
36 #if defined(_NETBSD_SOURCE)
37 #define O_SHLOCK 0x00000010 /* open with shared file lock */
38 #define O_EXLOCK 0x00000020 /* open with exclusive file lock */
39 #define O_ASYNC 0x00000040 /* signal pgrp when data ready */
41 #if (_POSIX_C_SOURCE - 0) >= 199309L || \
42 (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
43 (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
44 #define O_SYNC 0x00000080 /* synchronous writes */
46 #if defined(_NETBSD_SOURCE)
47 #define O_NOFOLLOW 0x00000100 /* don't follow symlinks on the last */
52 /* Oflag values for open(). POSIX Table 6-4. */
53 #define O_CREAT 00100 /* creat file if it doesn't exist */
54 #define O_EXCL 00200 /* exclusive use flag */
55 #define O_NOCTTY 00400 /* do not assign a controlling terminal */
56 #define O_TRUNC 01000 /* truncate flag */
58 #ifndef __minix /* NOT SUPPORTED! */
59 #if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \
60 defined(_NETBSD_SOURCE)
61 #define O_DSYNC 0x00010000 /* write: I/O data completion */
62 #define O_RSYNC 0x00020000 /* read: I/O completion as for write */
65 #if defined(_NETBSD_SOURCE)
66 #define O_ALT_IO 0x00040000 /* use alternate i/o semantics */
67 #define O_DIRECT 0x00080000 /* direct I/O hint */
72 * Constants used for fcntl(2)
76 /* These values are used for cmd in fcntl(). POSIX Table 6-1. */
77 #define F_DUPFD 0 /* duplicate file descriptor */
78 #define F_GETFD 1 /* get file descriptor flags */
79 #define F_SETFD 2 /* set file descriptor flags */
80 #define F_GETFL 3 /* get file status flags */
81 #define F_SETFL 4 /* set file status flags */
82 #define F_GETLK 5 /* get record locking information */
83 #define F_SETLK 6 /* set record locking information */
84 #define F_SETLKW 7 /* set record locking info; wait if blocked */
85 #define F_FREESP 8 /* free a section of a regular file */
87 /* File descriptor flags used for fcntl(). POSIX Table 6-2. */
88 #define FD_CLOEXEC 1 /* close on exec flag for third arg of fcntl */
90 /* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
91 #define F_RDLCK 1 /* shared or read lock */
92 #define F_WRLCK 2 /* exclusive or write lock */
93 #define F_UNLCK 3 /* unlock */
96 * Advisory file segment locking data type -
97 * information passed to system by user
100 short l_type
; /* type: F_RDLCK, F_WRLCK, or F_UNLCK */
101 short l_whence
; /* flag for starting offset */
102 off_t l_start
; /* relative offset in bytes */
103 off_t l_len
; /* size; if 0, then until EOF */
104 pid_t l_pid
; /* process id of the locks' owner */
107 #if defined(_NETBSD_SOURCE)
108 /* lock operations for flock(2) */
109 #define LOCK_SH F_RDLCK /* Shared lock */
110 #define LOCK_EX F_WRLCK /* Exclusive lock */
111 #define LOCK_NB 0x0080 /* Do not block when locking */
112 #define LOCK_UN F_UNLCK /* Unlock */
115 /* Always ensure that these are consistent with <stdio.h> and <unistd.h>! */
117 #define SEEK_SET 0 /* set file offset to offset */
120 #define SEEK_CUR 1 /* set file offset to current plus offset */
123 #define SEEK_END 2 /* set file offset to EOF plus offset */
126 #include <sys/cdefs.h>
129 int open(const char *, int, ...);
130 int creat(const char *, mode_t
);
131 int fcntl(int, int, ...);
132 #if defined(_NETBSD_SOURCE)
134 #endif /* _NETBSD_SOURCE */
137 #endif /* !_SYS_FCNTL_H_ */