source: branches/libc-0.6/src/emx/include/sys/fcntl.h

Last change on this file was 3809, checked in by bird, 11 years ago

0.6: s/const/const/g - just use the (now) standard 'const' everywhere in emx and kLIBC code. Avoid changing external code too much. fixes #279.

  • Property cvs2svn:cvs-rev set to 1.9
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 10.6 KB
Line 
1/* $Id: $ */
2/** @file
3 * FreeBSD 5.1 + EMX
4 *
5 * @changed bird: EMX isms.
6 * @changed bird: Removed (non KERNEL) stuff we don't implement and added
7 * EMX specific stuff.
8 * @changed bird: Added sys/stat.h if in XSI mode.
9 * @todo Consider implementing the flags and commands we don't currently
10 * include.
11 */
12
13
14/*-
15 * Copyright (c) 1983, 1990, 1993
16 * The Regents of the University of California. All rights reserved.
17 * (c) UNIX System Laboratories, Inc.
18 * All or some portions of this file are derived from material licensed
19 * to the University of California by American Telephone and Telegraph
20 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
21 * the permission of UNIX System Laboratories, Inc.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * This product includes software developed by the University of
34 * California, Berkeley and its contributors.
35 * 4. Neither the name of the University nor the names of its contributors
36 * may be used to endorse or promote products derived from this software
37 * without specific prior written permission.
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
40 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
48 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 *
51 * @(#)fcntl.h 8.3 (Berkeley) 1/21/94
52 * $FreeBSD: src/sys/sys/fcntl.h,v 1.14 2002/09/17 22:22:50 mike Exp $
53 */
54
55#ifndef _SYS_FCNTL_H_
56#define _SYS_FCNTL_H_
57#define _SYS_FCNTL_H /* bird: EMX */
58
59/*
60 * This file includes the definitions for open and fcntl
61 * described by POSIX for <fcntl.h>; it also includes
62 * related kernel definitions.
63 */
64
65#include <sys/cdefs.h>
66#include <sys/_types.h>
67#if __XSI_VISIBLE /* bird */
68#include <sys/stat.h> /* bird */
69#endif /* bird */
70
71#if !defined(_MODE_T_DECLARED) && !defined(_MODE_T) /* bird: EMX */
72typedef __mode_t mode_t;
73#define _MODE_T_DECLARED
74#define _MODE_T /* bird: EMX */
75#endif
76
77#if !defined(_OFF_T_DECLARED) && !defined(_OFF_T) /* bird: EMX */
78typedef __off_t off_t;
79#define _OFF_T_DECLARED
80#define _OFF_T /* bird: EMX */
81#endif
82
83#if !defined(_PID_T_DECLARED) && !defined(_PID_T) /* bird: EMX */
84typedef __pid_t pid_t;
85#define _PID_T_DECLARED
86#define _PID_T /* bird: EMX */
87#endif
88
89/*
90 * File status flags: these are used by open(2), fcntl(2).
91 * They are also used (indirectly) in the kernel file structure f_flags,
92 * which is a superset of the open/fcntl flags. Open flags and f_flags
93 * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
94 * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
95 */
96/* open-only flags */
97#define O_RDONLY 0x0000 /* open for reading only */
98#define O_WRONLY 0x0001 /* open for writing only */
99#define O_RDWR 0x0002 /* open for reading and writing */
100#define O_ACCMODE 0x0003 /* mask for above modes */
101
102/*
103 * Kernel encoding of open mode; separate read and write bits that are
104 * independently testable: 1 greater than the above.
105 *
106 * XXX
107 * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
108 * which was documented to use FREAD/FWRITE, continues to work.
109 */
110#if __BSD_VISIBLE
111#ifndef FREAD /* bird: safety */
112#define FREAD 0x0001
113#define FWRITE 0x0002
114#endif
115#endif /* bird: safety */
116#define O_NONBLOCK 0x0004 /* no delay */
117#define O_APPEND 0x0008 /* set append mode */
118#if __BSD_VISIBLE
119#if 0 /* bird: not implemented - start */
120#define O_SHLOCK 0x0010 /* open with shared file lock */
121#define O_EXLOCK 0x0020 /* open with exclusive file lock */
122#define O_ASYNC 0x0040 /* signal pgrp when data ready */
123#endif /* bird: not implemented - end */
124#define O_FSYNC 0x0080 /* synchronous writes */
125#endif
126/* bird: EMX used 0x2000 for O_SYNC. */
127#define O_SYNC 0x0080 /* POSIX synonym for O_FSYNC */
128#if __BSD_VISIBLE
129#define O_NOFOLLOW 0x0100 /* don't follow symlinks */
130#endif
131#define O_CREAT 0x0200 /* create if nonexistent */
132#define O_TRUNC 0x0400 /* truncate to zero length */
133#define O_EXCL 0x0800 /* error if already exists */
134#ifdef _KERNEL
135/* FMARK/FDEFER kept in f_gcflags */
136#define FMARK 0x1 /* mark during gc() */
137#define FDEFER 0x2 /* defer for next gc pass */
138#define FHASLOCK 0x4000 /* descriptor holds advisory lock */
139#endif
140
141/* Defined by POSIX 1003.1; BSD default, but must be distinct from O_RDONLY. */
142/* bird: EMX used 0x4000 for O_NOCTTY. */
143#define O_NOCTTY 0x8000 /* don't assign controlling terminal */
144
145#if __BSD_VISIBLE
146/* Attempt to bypass buffer cache */
147#define O_DIRECT 0x00010000
148#endif
149
150/*
151 * XXX missing O_DSYNC, O_RSYNC.
152 */
153
154#ifdef _KERNEL
155/* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
156#define FFLAGS(oflags) ((oflags) + 1)
157#define OFLAGS(fflags) ((fflags) - 1)
158
159/* bits to save after open */
160#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT)
161/* bits settable by fcntl(F_SETFL, ...) */
162#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|O_DIRECT)
163#endif
164
165/*
166 * The O_* flags used to have only F* names, which were used in the kernel
167 * and by fcntl. We retain the F* names for the kernel f_flag field
168 * and for backward compatibility for fcntl. These flags are deprecated.
169 */
170#if __BSD_VISIBLE
171#define FAPPEND O_APPEND /* kernel/compat */
172#if 0 /* bird: not implemented - start */
173#define FASYNC O_ASYNC /* kernel/compat */
174#endif /* bird: not implemented - end */
175#define FFSYNC O_FSYNC /* kernel */
176#define FNONBLOCK O_NONBLOCK /* kernel */
177#define FNDELAY O_NONBLOCK /* compat */
178#define O_NDELAY O_NONBLOCK /* compat */
179#endif
180
181#if 0 /* bird: not implemented - start */
182/*
183 * We are out of bits in f_flag (which is a short). However,
184 * the flag bits not set in FMASK are only meaningful in the
185 * initial open syscall. Those bits can thus be given a
186 * different meaning for fcntl(2).
187 */
188#if __BSD_VISIBLE
189
190/*
191 * Set by shm_open(3) to get automatic MAP_ASYNC behavior
192 * for POSIX shared memory objects (which are otherwise
193 * implemented as plain files).
194 */
195#define FPOSIXSHM O_NOFOLLOW
196#endif
197#endif /* bird: not implemented - end */
198
199/*
200 * Constants used for fcntl(2)
201 */
202
203/* command values */
204/* bird: EMX used 5 for F_DUPFD. */
205#define F_DUPFD 0 /* duplicate file descriptor */
206/* bird: EMX used 3 for F_GETFD. */
207#define F_GETFD 1 /* get file descriptor flags */
208/* bird: EMX used 4 for F_SETFD. */
209#define F_SETFD 2 /* set file descriptor flags */
210/* bird: EMX used 1 for F_GETFL. */
211#define F_GETFL 3 /* get file status flags */
212/* bird: EMX used 2 for F_SETFL. */
213#define F_SETFL 4 /* set file status flags */
214#if 0 /* bird: not implemented - start */
215#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
216#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */
217#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */
218#endif
219#endif /* bird: not implemented - end */
220#define F_GETLK 7 /* get record locking information */
221#define F_SETLK 8 /* set record locking information */
222#define F_SETLKW 9 /* F_SETLK; wait if blocked */
223
224
225/* file descriptor flags (F_GETFD, F_SETFD) */
226#define FD_CLOEXEC 1 /* close-on-exec flag */
227
228/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
229#define F_RDLCK 1 /* shared or read lock */
230#define F_UNLCK 2 /* unlock */
231#define F_WRLCK 3 /* exclusive or write lock */
232#ifdef _KERNEL
233#define F_WAIT 0x010 /* Wait until lock is granted */
234#define F_FLOCK 0x020 /* Use flock(2) semantics for lock */
235#define F_POSIX 0x040 /* Use POSIX semantics for lock */
236#endif
237
238/*
239 * Advisory file segment locking data type -
240 * information passed to system by user
241 */
242struct flock {
243 off_t l_start; /* starting offset */
244 off_t l_len; /* len = 0 means until end of file */
245 pid_t l_pid; /* lock owner */
246 short l_type; /* lock type: read/write, etc. */
247 short l_whence; /* type of l_start */
248};
249
250
251#if __BSD_VISIBLE
252/* lock operations for flock(2) */
253#define LOCK_SH 0x01 /* shared file lock */
254#define LOCK_EX 0x02 /* exclusive file lock */
255#define LOCK_NB 0x04 /* don't block when locking */
256#define LOCK_UN 0x08 /* unlock file */
257#endif
258
259/*
260 * XXX missing posix_fadvise() and posix_fallocate(), and POSIX_FADV_* macros.
261 */
262
263#ifndef _KERNEL
264__BEGIN_DECLS
265int open(const char *, int, ...);
266int creat(const char *, mode_t);
267int fcntl(int, int, ...);
268#if __BSD_VISIBLE
269int flock(int, int);
270#endif
271__END_DECLS
272#endif
273
274/* bird: EMX stuff - start */
275#if !defined (O_TEXT)
276/* Open flags.
277 * There is some limits to the available bits, generally FreeBSD limits
278 * it's range to the first 16-bits. See emx\io.h for the complete
279 * assignments.
280 */
281#define O_BINARY 0x00020000
282#define O_TEXT 0x00040000
283#define O_SIZE 0x00080000
284#if !defined (_POSIX_SOURCE) || defined(__USE_EMX)
285#define O_NOINHERIT 0x00001000
286#endif
287#endif
288
289#if !defined (F_OK) /* bird: Really defined in unistd.h, but Linux and EMX does it here too. */
290/* access function */
291#define F_OK 0 /* test for existence of file */
292#define X_OK 0x01 /* test for execute or search permission */
293#define W_OK 0x02 /* test for write permission */
294#define R_OK 0x04 /* test for read permission */
295#endif
296
297#if !defined (_POSIX_SOURCE) || defined (_WITH_UNDERSCORE) || defined(__USE_EMX)
298__BEGIN_DECLS
299int _creat (const char *, int);
300int _fcntl (int, int, ...);
301int _flock (int, int);
302int _open (const char *, int, ...);
303__END_DECLS
304#endif
305/* bird: EMX stuff - end */
306
307#endif /* !_SYS_FCNTL_H_ */
Note: See TracBrowser for help on using the repository browser.