fcntl.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _KERN_FCNTL_H_
  30. #define _KERN_FCNTL_H_
  31. /*
  32. * Constants for libc's <fcntl.h>.
  33. */
  34. /*
  35. * Important
  36. */
  37. /* Flags for open: choose one of these: */
  38. #define O_RDONLY 0 /* Open for read */
  39. #define O_WRONLY 1 /* Open for write */
  40. #define O_RDWR 2 /* Open for read and write */
  41. /* then or in any of these: */
  42. #define O_CREAT 4 /* Create file if it doesn't exist */
  43. #define O_EXCL 8 /* With O_CREAT, fail if file already exists */
  44. #define O_TRUNC 16 /* Truncate file upon open */
  45. #define O_APPEND 32 /* All writes happen at EOF (optional feature) */
  46. #define O_NOCTTY 64 /* Required by POSIX, != 0, but does nothing */
  47. /* Additional related definition */
  48. #define O_ACCMODE 3 /* mask for O_RDONLY/O_WRONLY/O_RDWR */
  49. /*
  50. * Not so important
  51. */
  52. /* operation codes for flock() */
  53. #define LOCK_SH 1 /* shared lock */
  54. #define LOCK_EX 2 /* exclusive lock */
  55. #define LOCK_UN 3 /* release the lock */
  56. #define LOCK_NB 4 /* flag: don't block */
  57. /*
  58. * Mostly pretty useless
  59. */
  60. /* fcntl() operations */
  61. #define F_DUPFD 0 /* like dup() but not quite */
  62. #define F_GETFD 1 /* get per-handle flags */
  63. #define F_SETFD 2 /* set per-handle flags */
  64. #define F_GETFL 3 /* get per-file flags (O_* open flags) */
  65. #define F_SETFL 4 /* set per-file flags (O_* open flags) */
  66. #define F_GETOWN 5 /* get process/pgroup for SIGURG and SIGIO */
  67. #define F_SETOWN 6 /* set process/pgroup for SIGURG and SIGIO */
  68. #define F_GETLK 7 /* inspect record locks */
  69. #define F_SETLK 8 /* acquire record locks nonblocking */
  70. #define F_SETLKW 9 /* acquire record locks and wait */
  71. /* flag for F_GETFD and F_SETFD */
  72. #define FD_CLOEXEC 1 /* close-on-exec */
  73. /* modes for fcntl (F_GETLK/SETLK) locking */
  74. #define F_RDLCK 0 /* shared lock */
  75. #define F_WRLCK 1 /* exclusive lock */
  76. #define F_UNLCK 2 /* unlock */
  77. /* struct for fcntl (F_GETLK/SETLK) locking */
  78. struct flock {
  79. off_t l_start; /* place in file */
  80. int l_whence; /* SEEK_SET, SEEK_CUR, or SEEK_END */
  81. int l_type; /* F_RDLCK or F_WRLCK */
  82. off_t l_len; /* length of locked region */
  83. pid_t l_pid; /* process that holds the lock */
  84. };
  85. #endif /* _KERN_FCNTL_H_ */