00001 /* The <fcntl.h> header is needed by the open() and fcntl() system calls, 00002 * which have a variety of parameters and flags. They are described here. 00003 * The formats of the calls to each of these are: 00004 * 00005 * open(path, oflag [,mode]) open a file 00006 * fcntl(fd, cmd [,arg]) get or set file attributes 00007 * 00008 */ 00009 00010 #ifndef _FCNTL_H 00011 #define _FCNTL_H 00012 00013 #ifndef _TYPES_H 00014 #include <sys/types.h> 00015 #endif 00016 00017 /* These values are used for cmd in fcntl(). POSIX Table 6-1. */ 00018 #define F_DUPFD 0 /* duplicate file descriptor */ 00019 #define F_GETFD 1 /* get file descriptor flags */ 00020 #define F_SETFD 2 /* set file descriptor flags */ 00021 #define F_GETFL 3 /* get file status flags */ 00022 #define F_SETFL 4 /* set file status flags */ 00023 #define F_GETLK 5 /* get record locking information */ 00024 #define F_SETLK 6 /* set record locking information */ 00025 #define F_SETLKW 7 /* set record locking info; wait if blocked */ 00026 #define F_FREESP 8 /* free a section of a regular file */ 00027 00028 /* File descriptor flags used for fcntl(). POSIX Table 6-2. */ 00029 #define FD_CLOEXEC 1 /* close on exec flag for third arg of fcntl */ 00030 00031 /* L_type values for record locking with fcntl(). POSIX Table 6-3. */ 00032 #define F_RDLCK 1 /* shared or read lock */ 00033 #define F_WRLCK 2 /* exclusive or write lock */ 00034 #define F_UNLCK 3 /* unlock */ 00035 00036 /* Oflag values for open(). POSIX Table 6-4. */ 00037 #define O_CREAT 00100 /* creat file if it doesn't exist */ 00038 #define O_EXCL 00200 /* exclusive use flag */ 00039 #define O_NOCTTY 00400 /* do not assign a controlling terminal */ 00040 #define O_TRUNC 01000 /* truncate flag */ 00041 00042 /* File status flags for open() and fcntl(). POSIX Table 6-5. */ 00043 #define O_APPEND 02000 /* set append mode */ 00044 #define O_NONBLOCK 04000 /* no delay */ 00045 00046 /* File access modes for open() and fcntl(). POSIX Table 6-6. */ 00047 #define O_RDONLY 0 /* open(name, O_RDONLY) opens read only */ 00048 #define O_WRONLY 1 /* open(name, O_WRONLY) opens write only */ 00049 #define O_RDWR 2 /* open(name, O_RDWR) opens read/write */ 00050 00051 /* Mask for use with file access modes. POSIX Table 6-7. */ 00052 #define O_ACCMODE 03 /* mask for file access modes */ 00053 00054 /* Struct used for locking. POSIX Table 6-8. */ 00055 struct flock { 00056 short l_type; /* type: F_RDLCK, F_WRLCK, or F_UNLCK */ 00057 short l_whence; /* flag for starting offset */ 00058 off_t l_start; /* relative offset in bytes */ 00059 off_t l_len; /* size; if 0, then until EOF */ 00060 pid_t l_pid; /* process id of the locks' owner */ 00061 }; 00062 00063 /* Function Prototypes. */ 00064 _PROTOTYPE( int creat, (const char *_path, _mnx_Mode_t _mode) ); 00065 _PROTOTYPE( int fcntl, (int _filedes, int _cmd, ...) ); 00066 _PROTOTYPE( int open, (const char *_path, int _oflag, ...) ); 00067 00068 /* For locking files. */ 00069 #define LOCK_SH F_RDLCK /* Shared lock */ 00070 #define LOCK_EX F_WRLCK /* Exclusive lock */ 00071 #define LOCK_NB 0x0080 /* Do not block when locking */ 00072 #define LOCK_UN F_UNLCK /* Unlock */ 00073 00074 _PROTOTYPE( int flock, (int fd, int mode) ); 00075 00076 #endif /* _FCNTL_H */
1.4.6