home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * $Source: /unixb/home/unixlib/source/unixlib37/clib/h/RCS/fcntl,v $
- * $Date: 1996/10/30 21:58:58 $
- * $Revision: 1.3 $
- * $State: Exp $
- * $Author: unixlib $
- *
- * $Log: fcntl,v $
- * Revision 1.3 1996/10/30 21:58:58 unixlib
- * Massive changes made by Nick Burret and Peter Burwood.
- *
- * Revision 1.2 1996/07/21 22:15:12 unixlib
- * CL_0001 Nick Burret
- * Improve memory handling. Remove C++ library incompatibilities.
- * Improve file stat routines.
- *
- * Revision 1.1 1996/04/19 21:02:57 simon
- * Initial revision
- *
- ***************************************************************************/
-
- /* POSIX Standard 6.5: File Control Operations <fcntl.h> */
-
- #ifndef __FCNTL_H
- #define __FCNTL_H
-
- #ifndef __LIBC_TYPES_H
- #include <libc/types.h>
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- /* These fcntlbits are derived from 4.4 BSD. */
-
- #define O_OMASK 3
-
- /* File access modes for open and fcntl. */
-
- /* Open for read only. */
- #define O_RDONLY 0
- /* Open for write only. */
- #define O_WRONLY 1
- /* Open for read/write. */
- #define O_RDWR 2
-
- /* Bits OR'd into the second argument to open. */
-
- /* Create file if it doesn't exist. */
- #define O_CREAT 0x0200
- /* Fail if file already exists. */
- #define O_EXCL 0x0800
- /* Truncate file to zero length. */
- #define O_TRUNC 0x0400
- /* Send SIGIO to owner when data is ready. */
- #define O_ASYNC 0x0040
- /* Synchronous writes. */
- #define O_FSYNC 0x0080
- #define O_SYNC O_FSYNC
- /* Open with shared file lock. */
- #define O_SHLOCK 0x0010
- /* Open with shared exclusive lock. */
- #define O_EXLOCK 0x0020
-
- /* File status flags for open and fcntl. */
-
- /* Writes append to the file. */
- #define O_APPEND 0x0008
- /* Non-blocking I/O. */
- #define O_NONBLOCK 0x0004
- #define O_NDELAY O_NONBLOCK
-
- /* close on exec() flag - must be bit 8 */
- #define O_EXECCL 0x0100
-
- #define O_BINARY 0x2000
- #define O_TEXT 0x1000
-
- #define O_PIPE 0x4000 /* UnixLib specific */
-
- /* Mask for file access modes. This is system-dependent in case
- some system ever wants to define some other flavor of access. */
- #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
-
-
- /* Duplicate file descriptor. */
- #define F_DUPFD 0
- /* Return file descriptor flags. */
- #define F_GETFD 1
- /* Set file descriptor flags. */
- #define F_SETFD 2
- /* Read file status flags. */
- #define F_GETFL 3
- /* Set file status flags. */
- #define F_SETFL 4
- /* Get owner (receiver of SIGIO). */
- #define F_GETOWN 5
- /* Set owner (receiver of SIGIO). */
- #define F_SETOWN 6
- /* Get record locking info. */
- #define F_GETLK 7
- /* Set record locking info (non-blocking). */
- #define F_SETLK 8
- /* Set record locking info (blocking). */
- #define F_SETLKW 9
-
- /* Bits in the file status flags returned by F_GETFL. */
- #define FREAD 1
- #define FWRITE 2
-
- /* Traditional BSD names the O_* bits. */
- #define FASYNC O_ASYNC
- #define FCREAT O_CREAT
- #define FEXCL O_EXCL
- #define FTRUNC O_TRUNC
- #define FNOCTTY O_NOCTTY
- #define FFSYNC O_FSYNC
- #define FSYNC O_SYNC
- #define FAPPEND O_APPEND
- #define FNONBLOCK O_NONBLOCK
- #define FNDELAY O_NDELAY
-
-
- /* If set, cause the file descriptor to be closed if an exec function
- is used. Initially, set clear. */
- #define FD_CLOEXEC O_EXECCL
-
- /* The structure describing an advisory lock. This is the type of the third
- argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests. */
- struct flock
- {
- /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
- short int l_type;
- /* Where `l_start' is relative to (like `lseek'). */
- short int l_whence;
- /* Offset where the lock begins. */
- __off_t l_start;
- /* Size of the locked area; zero means until EOF. */
- __off_t l_len;
- /* Process holding the lock. */
- short int l_pid;
- };
-
- /* Values for the `l_type' field of a `struct flock'. */
- #define F_RDLCK 1 /* Read lock. */
- #define F_WRLCK 2 /* Write lock. */
- #define F_UNLCK 3 /* Remove lock. */
-
-
- #ifndef R_OK
- /* Straight from <unistd.h>. */
-
- /* Values for the second argument to access.
- These may be OR'd together. */
-
- /* Test for read permission. */
- #define R_OK 4
- /* Test for write permission. */
- #define W_OK 2
- /* Test for execute permission. */
- #define X_OK 1
- /* Test for existence. */
- #define F_OK 0
- #endif
-
-
- /* Do the file control operation described by CMD on FD.
- The remaining arguments are interpreted depending on CMD. */
- extern int fcntl (int fd, int cmd, ...);
-
- /* Open FILE and return a new file descriptor for it, or -1 on error.
- OFLAG determines the type of access used. If O_CREAT is on OFLAG,
- the third argument is taken as a `mode_t', the mode of the created file. */
- extern int open (const char *file, int oflag, ...);
-
- /* Create and open FILE, with mode MODE.
- This takes an `int' MODE argument because that is
- what `mode_t' will be widened to. */
- extern int creat (const char *file, __mode_t mode);
-
- #ifndef F_LOCK
- /* These declarations also appear in <unistd.h>; be sure to keep both
- files consistent. */
-
- /* `lockf' is a simpler interface to the locking facilities of `fcntl'.
- LEN is always relative to the current file position.
- The CMD argument is one of the following. */
-
- #define F_ULOCK 0 /* Unlock a previously locked region. */
- #define F_LOCK 1 /* Lock a region for exclusive use. */
- #define F_TLOCK 2 /* Test and lock a region for exclusive use. */
- #define F_TEST 3 /* Test a region for other processes locks. */
-
- extern int lockf (int fd, int cmd, __off_t len);
- #endif
-
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif
-