1 /* This file is to be kept in sync with newlib/libc/include/sys/fcntl.h,
2    on which it is based, except values used or returned by syscalls must
3    be those of the Linux/CRIS kernel.  */
4 
5 #ifndef	_FCNTL_
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 #define	_FCNTL_
10 #include <_ansi.h>
11 #define	_FOPEN		(-1)	/* from sys/file.h, kernel use only */
12 #define	_FREAD		0x0001	/* read enabled */
13 #define	_FWRITE		0x0002	/* write enabled */
14 #define	_FNDELAY	0x0800	/* non blocking I/O (4.2 style) */
15 #define	_FAPPEND	0x0400	/* append (writes guaranteed at the end) */
16 #define	_FMARK		0x0010	/* internal; mark during gc() */
17 #define	_FDEFER		0x0020	/* internal; defer for next gc pass */
18 #define	_FASYNC		0x2000	/* signal pgrp when data ready */
19 #define	_FCREAT		0x0040	/* open with file create */
20 #define	_FTRUNC		0x0200	/* open with truncation */
21 #define	_FEXCL		0x0080	/* error on open if file exists */
22 #define	_FNBIO	    _FNONBLOCK	/* non blocking I/O (sys5 style) */
23 #define	_FSYNC		0x1000	/* do all writes synchronously */
24 #define	_FNONBLOCK	0x0800	/* non blocking I/O (POSIX style) */
25 #define	_FNOCTTY	0x0100	/* don't assign a ctty on this open */
26 
27 #define	O_ACCMODE	(O_RDONLY|O_WRONLY|O_RDWR)
28 
29 /*
30  * Flag values for open(2) and fcntl(2)
31  * The kernel adds 1 to the open modes to turn it into some
32  * combination of FREAD and FWRITE.
33  */
34 #define	O_RDONLY	0		/* +1 == FREAD */
35 #define	O_WRONLY	1		/* +1 == FWRITE */
36 #define	O_RDWR		2		/* +1 == FREAD|FWRITE */
37 #define	O_APPEND	_FAPPEND
38 #define	O_CREAT		_FCREAT
39 #define	O_TRUNC		_FTRUNC
40 #define	O_EXCL		_FEXCL
41 /*	O_SYNC		_FSYNC		not posix, defined below */
42 /*	O_NDELAY	_FNDELAY 	set in include/fcntl.h */
43 /*	O_NDELAY	_FNBIO 		set in 5include/fcntl.h */
44 #define	O_NONBLOCK	_FNONBLOCK
45 #define	O_NOCTTY	_FNOCTTY
46 
47 #ifndef	_POSIX_SOURCE
48 
49 #define	O_SYNC		_FSYNC
50 
51 /*
52  * Flags that work for fcntl(fd, F_SETFL, FXXXX)
53  */
54 #define	FAPPEND		_FAPPEND
55 #define	FSYNC		_FSYNC
56 #define	FASYNC		_FASYNC
57 #define	FNBIO		_FNBIO
58 #define	FNONBIO		_FNONBLOCK	/* XXX fix to be NONBLOCK everywhere */
59 #define	FNDELAY		_FNDELAY
60 
61 /*
62  * Flags that are disallowed for fcntl's (FCNTLCANT);
63  * used for opens, internal state, or locking.
64  */
65 #define	FREAD		_FREAD
66 #define	FWRITE		_FWRITE
67 #define	FMARK		_FMARK
68 #define	FDEFER		_FDEFER
69 #define	FSHLOCK		_FSHLOCK
70 #define	FEXLOCK		_FEXLOCK
71 
72 /*
73  * The rest of the flags, used only for opens
74  */
75 #define	FOPEN		_FOPEN
76 #define	FCREAT		_FCREAT
77 #define	FTRUNC		_FTRUNC
78 #define	FEXCL		_FEXCL
79 #define	FNOCTTY		_FNOCTTY
80 
81 #endif	/* !_POSIX_SOURCE */
82 
83 /* XXX close on exec request; must match UF_EXCLOSE in user.h */
84 #define	FD_CLOEXEC	1	/* posix */
85 
86 /* fcntl(2) requests */
87 #define F_DUPFD		0	/* dup */
88 #define F_GETFD		1	/* get f_flags */
89 #define F_SETFD		2	/* set f_flags */
90 #define F_GETFL		3	/* more flags (cloexec) */
91 #define F_SETFL		4
92 #define F_GETLK		5
93 #define F_SETLK		6
94 #define F_SETLKW	7
95 
96 #define F_SETOWN	8	/*  for sockets. */
97 #define F_GETOWN	9	/*  for sockets. */
98 
99 /* for F_[GET|SET]FL */
100 #define FD_CLOEXEC	1	/* actually anything with low bit set goes */
101 
102 /* for posix fcntl() and lockf() */
103 #define F_RDLCK		0
104 #define F_WRLCK		1
105 #define F_UNLCK		2
106 
107 /* for old implementation of bsd flock () */
108 #define F_EXLCK		4	/* or 3 */
109 #define F_SHLCK		8	/* or 4 */
110 
111 /* operations for bsd flock(), also used by the kernel implementation */
112 #define LOCK_SH		1	/* shared lock */
113 #define LOCK_EX		2	/* exclusive lock */
114 #define LOCK_NB		4	/* or'd with one of the above to prevent
115 				   blocking */
116 #define LOCK_UN		8	/* remove lock */
117 
118 /* file segment locking set data type - information passed to system by user */
119 struct flock {
120 	short	l_type;		/* F_RDLCK, F_WRLCK, or F_UNLCK */
121 	short	l_whence;	/* flag to choose starting offset */
122 	long	l_start;	/* relative offset, in bytes */
123 	long	l_len;		/* length, in bytes; 0 means lock to EOF */
124 	short	l_pid;		/* returned with F_GETLK */
125 	short	l_xxx;		/* reserved for future use */
126 };
127 
128 #ifndef	_POSIX_SOURCE
129 /* extended file segment locking set data type */
130 struct eflock {
131 	short	l_type;		/* F_RDLCK, F_WRLCK, or F_UNLCK */
132 	short	l_whence;	/* flag to choose starting offset */
133 	long	l_start;	/* relative offset, in bytes */
134 	long	l_len;		/* length, in bytes; 0 means lock to EOF */
135 	short	l_pid;		/* returned with F_GETLK */
136 	short	l_xxx;		/* reserved for future use */
137 	long	l_rpid;		/* Remote process id wanting this lock */
138 	long	l_rsys;		/* Remote system id wanting this lock */
139 };
140 #endif	/* !_POSIX_SOURCE */
141 
142 
143 #include <sys/types.h>
144 #include <sys/stat.h>		/* sigh. for the mode bits for open/creat */
145 
146 extern int open _PARAMS ((const char *, int, ...));
147 extern int creat _PARAMS ((const char *, mode_t));
148 extern int fcntl _PARAMS ((int, int, ...));
149 
150 /* Provide _<systemcall> prototypes for functions provided by some versions
151    of newlib.  */
152 #ifdef _COMPILING_NEWLIB
153 extern int _open _PARAMS ((const char *, int, ...));
154 extern int _fcntl _PARAMS ((int, int, ...));
155 #ifdef __LARGE64_FILES
156 extern int _open64 _PARAMS ((const char *, int, ...));
157 #endif
158 #endif
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 #endif	/* !_FCNTL_ */
164