stat.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* Copyright (C) 1991, 92, 1995-1999, 2000, 2001 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /*
  16. * POSIX Standard: 5.6 File Characteristics <sys/stat.h>
  17. */
  18. #ifndef _SYS_STAT_H
  19. #define _SYS_STAT_H 1
  20. #include <features.h>
  21. #include <bits/types.h> /* For __mode_t and __dev_t. */
  22. #ifdef __USE_XOPEN
  23. # define __need_time_t
  24. # include <time.h> /* For time_t. */
  25. /* The Single Unix specification says that some more types are
  26. available here. */
  27. # ifndef __dev_t_defined
  28. typedef __dev_t dev_t;
  29. # define __dev_t_defined
  30. # endif
  31. # ifndef __gid_t_defined
  32. typedef __gid_t gid_t;
  33. # define __gid_t_defined
  34. # endif
  35. # ifndef __ino_t_defined
  36. # ifndef __USE_FILE_OFFSET64
  37. typedef __ino_t ino_t;
  38. # else
  39. typedef __ino64_t ino_t;
  40. # endif
  41. # define __ino_t_defined
  42. # endif
  43. # ifndef __mode_t_defined
  44. typedef __mode_t mode_t;
  45. # define __mode_t_defined
  46. # endif
  47. # ifndef __nlink_t_defined
  48. typedef __nlink_t nlink_t;
  49. # define __nlink_t_defined
  50. # endif
  51. # ifndef __off_t_defined
  52. # ifndef __USE_FILE_OFFSET64
  53. typedef __off_t off_t;
  54. # else
  55. typedef __off64_t off_t;
  56. # endif
  57. # define __off_t_defined
  58. # endif
  59. # ifndef __uid_t_defined
  60. typedef __uid_t uid_t;
  61. # define __uid_t_defined
  62. # endif
  63. #endif /* X/Open */
  64. #ifdef __USE_UNIX98
  65. # ifndef __blkcnt_t_defined
  66. # ifndef __USE_FILE_OFFSET64
  67. typedef __blkcnt_t blkcnt_t;
  68. # else
  69. typedef __blkcnt64_t blkcnt_t;
  70. # endif
  71. # define __blkcnt_t_defined
  72. # endif
  73. # ifndef __blksize_t_defined
  74. typedef __blksize_t blksize_t;
  75. # define __blksize_t_defined
  76. # endif
  77. #endif /* Unix98 */
  78. __BEGIN_DECLS
  79. #include <bits/stat.h>
  80. #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
  81. # define S_IFMT __S_IFMT
  82. # define S_IFDIR __S_IFDIR
  83. # define S_IFCHR __S_IFCHR
  84. # define S_IFBLK __S_IFBLK
  85. # define S_IFREG __S_IFREG
  86. # ifdef __S_IFIFO
  87. # define S_IFIFO __S_IFIFO
  88. # endif
  89. # ifdef __S_IFLNK
  90. # define S_IFLNK __S_IFLNK
  91. # endif
  92. # if (defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN2K) \
  93. && defined __S_IFSOCK
  94. # define S_IFSOCK __S_IFSOCK
  95. # endif
  96. #endif
  97. /* Test macros for file types. */
  98. #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
  99. #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
  100. #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR)
  101. #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK)
  102. #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
  103. #ifdef __S_IFIFO
  104. # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
  105. #endif
  106. #ifdef __S_IFLNK
  107. # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
  108. #endif
  109. #ifdef __USE_BSD
  110. # ifndef __S_IFLNK
  111. # define S_ISLNK(mode) 0
  112. # endif
  113. # ifdef __S_IFSOCK
  114. # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
  115. # endif
  116. #endif
  117. /* These are from POSIX.1b. If the objects are not implemented using separate
  118. distinct file types, the macros always will evaluate to zero. Unlike the
  119. other S_* macros the following three take a pointer to a `struct stat'
  120. object as the argument. */
  121. #ifdef __USE_POSIX199309
  122. # define S_TYPEISMQ(buf) __S_TYPEISMQ(buf)
  123. # define S_TYPEISSEM(buf) __S_TYPEISSEM(buf)
  124. # define S_TYPEISSHM(buf) __S_TYPEISSHM(buf)
  125. #endif
  126. /* Protection bits. */
  127. #define S_ISUID __S_ISUID /* Set user ID on execution. */
  128. #define S_ISGID __S_ISGID /* Set group ID on execution. */
  129. #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
  130. /* Save swapped text after use (sticky bit). This is pretty well obsolete. */
  131. # define S_ISVTX __S_ISVTX
  132. #endif
  133. #define S_IRUSR __S_IREAD /* Read by owner. */
  134. #define S_IWUSR __S_IWRITE /* Write by owner. */
  135. #define S_IXUSR __S_IEXEC /* Execute by owner. */
  136. /* Read, write, and execute by owner. */
  137. #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
  138. #if defined __USE_MISC && defined __USE_BSD
  139. # define S_IREAD S_IRUSR
  140. # define S_IWRITE S_IWUSR
  141. # define S_IEXEC S_IXUSR
  142. #endif
  143. #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
  144. #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
  145. #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
  146. /* Read, write, and execute by group. */
  147. #define S_IRWXG (S_IRWXU >> 3)
  148. #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
  149. #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
  150. #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
  151. /* Read, write, and execute by others. */
  152. #define S_IRWXO (S_IRWXG >> 3)
  153. #ifdef __USE_BSD
  154. /* Macros for common mode bit masks. */
  155. # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
  156. # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
  157. # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
  158. # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
  159. #endif
  160. #ifndef __USE_FILE_OFFSET64
  161. /* Get file attributes for FILE and put them in BUF. */
  162. extern int stat (__const char *__restrict __file,
  163. struct stat *__restrict __buf) __THROW;
  164. /* Get file attributes for the file, device, pipe, or socket
  165. that file descriptor FD is open on and put them in BUF. */
  166. extern int fstat (int __fd, struct stat *__buf) __THROW;
  167. #else
  168. # ifdef __REDIRECT
  169. extern int __REDIRECT (stat,
  170. (__const char *__restrict __file,
  171. struct stat *__restrict __buf) __THROW,
  172. stat64);
  173. extern int __REDIRECT (fstat, (int __fd, struct stat *__buf) __THROW, fstat64);
  174. # else
  175. # define stat stat64
  176. # define fstat fstat64
  177. # endif
  178. #endif
  179. #ifdef __USE_LARGEFILE64
  180. extern int stat64 (__const char *__restrict __file,
  181. struct stat64 *__restrict __buf) __THROW;
  182. extern int fstat64 (int __fd, struct stat64 *__buf) __THROW;
  183. #endif
  184. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  185. # ifndef __USE_FILE_OFFSET64
  186. /* Get file attributes about FILE and put them in BUF.
  187. If FILE is a symbolic link, do not follow it. */
  188. extern int lstat (__const char *__restrict __file,
  189. struct stat *__restrict __buf) __THROW;
  190. # else
  191. # ifdef __REDIRECT
  192. extern int __REDIRECT (lstat,
  193. (__const char *__restrict __file,
  194. struct stat *__restrict __buf) __THROW,
  195. lstat64);
  196. # else
  197. # define lstat lstat64
  198. # endif
  199. # endif
  200. # ifdef __USE_LARGEFILE64
  201. extern int lstat64 (__const char *__restrict __file,
  202. struct stat64 *__restrict __buf) __THROW;
  203. # endif
  204. #endif
  205. /* Set file access permissions for FILE to MODE.
  206. This takes an `int' MODE argument because that
  207. is what `mode_t's get widened to. */
  208. extern int chmod (__const char *__file, __mode_t __mode) __THROW;
  209. /* Set file access permissions of the file FD is open on to MODE. */
  210. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  211. extern int fchmod (int __fd, __mode_t __mode) __THROW;
  212. #endif
  213. /* Set the file creation mask of the current process to MASK,
  214. and return the old creation mask. */
  215. extern __mode_t umask (__mode_t __mask) __THROW;
  216. #ifdef __USE_GNU
  217. /* Get the current `umask' value without changing it.
  218. This function is only available under the GNU Hurd. */
  219. extern __mode_t getumask (void) __THROW;
  220. #endif
  221. /* Create a new directory named PATH, with permission bits MODE. */
  222. extern int mkdir (__const char *__path, __mode_t __mode) __THROW;
  223. /* Create a device file named PATH, with permission and special bits MODE
  224. and device number DEV (which can be constructed from major and minor
  225. device numbers with the `makedev' macro above). */
  226. #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  227. extern int mknod (__const char *__path, __mode_t __mode, __dev_t __dev)
  228. __THROW;
  229. #endif
  230. /* Create a new FIFO named PATH, with permission bits MODE. */
  231. extern int mkfifo (__const char *__path, __mode_t __mode) __THROW;
  232. __END_DECLS
  233. #endif /* sys/stat.h */