fcntl.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* The <fcntl.h> header is needed by the open() and fcntl() system calls,
  2. * which have a variety of parameters and flags. They are described here.
  3. * The formats of the calls to each of these are:
  4. *
  5. * open(path, oflag [,mode]) open a file
  6. * fcntl(fd, cmd [,arg]) get or set file attributes
  7. *
  8. */
  9. #ifndef _FCNTL_H
  10. #define _FCNTL_H
  11. /* These values are used for cmd in fcntl(). POSIX Table 6-1. */
  12. #define F_DUPFD 0 /* duplicate file descriptor */
  13. #define F_GETFD 1 /* get file descriptor flags */
  14. #define F_SETFD 2 /* set file descriptor flags */
  15. #define F_GETFL 3 /* get file status flags */
  16. #define F_SETFL 4 /* set file status flags */
  17. #define F_GETLK 5 /* get record locking information */
  18. #define F_SETLK 6 /* set record locking information */
  19. #define F_SETLKW 7 /* set record locking info; wait if blocked */
  20. /* File descriptor flags used for fcntl(). POSIX Table 6-2. */
  21. #define FD_CLOEXEC 1 /* close on exec flag for third arg of fcntl */
  22. /* L_type values for record locking with fcntl(). POSIX Table 6-3. */
  23. #define F_RDLCK 0 /* shared or read lock */
  24. #define F_WRLCK 1 /* exclusive or write lock */
  25. #define F_UNLCK 2 /* unlock */
  26. /* Oflag values for open(). POSIX Table 6-4. */
  27. #define O_CREAT 00100 /* creat file if it doesn't exist */
  28. #define O_EXCL 00200 /* exclusive use flag */
  29. #define O_NOCTTY 00400 /* do not assign a controlling terminal */
  30. #define O_TRUNC 01000 /* truncate flag */
  31. /* File status flags for open() and fcntl(). POSIX Table 6-5. */
  32. #define O_APPEND 02000 /* set append mode */
  33. #define O_NONBLOCK 04000 /* no delay */
  34. /* File access modes for open() and fcntl(). POSIX Table 6-6. */
  35. #define O_RDONLY 0 /* open(name, O_RDONLY) opens read only */
  36. #define O_WRONLY 1 /* open(name, O_WRONLY) opens write only */
  37. #define O_RDWR 2 /* open(name, O_RDWR) opens read/write */
  38. /* Mask for use with file access modes. POSIX Table 6-7. */
  39. #define O_ACCMODE 03 /* mask for file access modes */
  40. /* Struct used for locking. POSIX Table 6-8. */
  41. struct flock {
  42. short l_type; /* type: F_RDLCK, F_WRLCK, or F_UNLCK */
  43. short l_whence; /* flag for starting offset */
  44. off_t l_start; /* relative offset in bytes */
  45. off_t l_len; /* size; if 0, then until EOF */
  46. pid_t l_pid; /* process id of the locks' owner */
  47. };
  48. /* Function Prototypes. */
  49. #ifndef _ANSI_H
  50. #include <ansi.h>
  51. #endif
  52. _PROTOTYPE( int creat, (const char *_path, Mode_t _mode) );
  53. _PROTOTYPE( int fcntl, (int _filedes, int _cmd, ...) );
  54. _PROTOTYPE( int open, (const char *_path, int _oflag, ...) );
  55. #endif /* _FCNTL_H */