stat.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /* Copyright (C) 1991,1992,1995-2002,2003,2004 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. #if defined __USE_XOPEN || defined __USE_MISC
  23. # if defined __USE_XOPEN || defined __USE_XOPEN2K
  24. # define __need_time_t
  25. # endif
  26. # ifdef __USE_MISC
  27. # define __need_timespec
  28. # endif
  29. # include <time.h> /* For time_t resp. timespec. */
  30. #endif
  31. #if defined __USE_XOPEN || defined __USE_XOPEN2K
  32. /* The Single Unix specification says that some more types are
  33. available here. */
  34. # ifndef __dev_t_defined
  35. typedef __dev_t dev_t;
  36. # define __dev_t_defined
  37. # endif
  38. # ifndef __gid_t_defined
  39. typedef __gid_t gid_t;
  40. # define __gid_t_defined
  41. # endif
  42. # ifndef __ino_t_defined
  43. # ifndef __USE_FILE_OFFSET64
  44. typedef __ino_t ino_t;
  45. # else
  46. typedef __ino64_t ino_t;
  47. # endif
  48. # define __ino_t_defined
  49. # endif
  50. # ifndef __mode_t_defined
  51. typedef __mode_t mode_t;
  52. # define __mode_t_defined
  53. # endif
  54. # ifndef __nlink_t_defined
  55. typedef __nlink_t nlink_t;
  56. # define __nlink_t_defined
  57. # endif
  58. # ifndef __off_t_defined
  59. # ifndef __USE_FILE_OFFSET64
  60. typedef __off_t off_t;
  61. # else
  62. typedef __off64_t off_t;
  63. # endif
  64. # define __off_t_defined
  65. # endif
  66. # ifndef __uid_t_defined
  67. typedef __uid_t uid_t;
  68. # define __uid_t_defined
  69. # endif
  70. #endif /* X/Open */
  71. #ifdef __USE_UNIX98
  72. # ifndef __blkcnt_t_defined
  73. # ifndef __USE_FILE_OFFSET64
  74. typedef __blkcnt_t blkcnt_t;
  75. # else
  76. typedef __blkcnt64_t blkcnt_t;
  77. # endif
  78. # define __blkcnt_t_defined
  79. # endif
  80. # ifndef __blksize_t_defined
  81. typedef __blksize_t blksize_t;
  82. # define __blksize_t_defined
  83. # endif
  84. #endif /* Unix98 */
  85. __BEGIN_DECLS
  86. #include <bits/stat.h>
  87. #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
  88. # define S_IFMT __S_IFMT
  89. # define S_IFDIR __S_IFDIR
  90. # define S_IFCHR __S_IFCHR
  91. # define S_IFBLK __S_IFBLK
  92. # define S_IFREG __S_IFREG
  93. # ifdef __S_IFIFO
  94. # define S_IFIFO __S_IFIFO
  95. # endif
  96. # ifdef __S_IFLNK
  97. # define S_IFLNK __S_IFLNK
  98. # endif
  99. # if (defined __USE_BSD || defined __USE_MISC || defined __USE_UNIX98) \
  100. && defined __S_IFSOCK
  101. # define S_IFSOCK __S_IFSOCK
  102. # endif
  103. #endif
  104. /* Test macros for file types. */
  105. #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
  106. #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
  107. #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR)
  108. #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK)
  109. #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
  110. #ifdef __S_IFIFO
  111. # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
  112. #endif
  113. #ifdef __S_IFLNK
  114. # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
  115. #endif
  116. #if defined __USE_BSD && !defined __S_IFLNK
  117. # define S_ISLNK(mode) 0
  118. #endif
  119. #if (defined __USE_BSD || defined __USE_UNIX98) \
  120. && defined __S_IFSOCK
  121. # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
  122. #endif
  123. /* These are from POSIX.1b. If the objects are not implemented using separate
  124. distinct file types, the macros always will evaluate to zero. Unlike the
  125. other S_* macros the following three take a pointer to a `struct stat'
  126. object as the argument. */
  127. #ifdef __USE_POSIX199309
  128. # define S_TYPEISMQ(buf) __S_TYPEISMQ(buf)
  129. # define S_TYPEISSEM(buf) __S_TYPEISSEM(buf)
  130. # define S_TYPEISSHM(buf) __S_TYPEISSHM(buf)
  131. #endif
  132. /* Protection bits. */
  133. #define S_ISUID __S_ISUID /* Set user ID on execution. */
  134. #define S_ISGID __S_ISGID /* Set group ID on execution. */
  135. #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
  136. /* Save swapped text after use (sticky bit). This is pretty well obsolete. */
  137. # define S_ISVTX __S_ISVTX
  138. #endif
  139. #define S_IRUSR __S_IREAD /* Read by owner. */
  140. #define S_IWUSR __S_IWRITE /* Write by owner. */
  141. #define S_IXUSR __S_IEXEC /* Execute by owner. */
  142. /* Read, write, and execute by owner. */
  143. #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
  144. #if defined __USE_MISC && defined __USE_BSD
  145. # define S_IREAD S_IRUSR
  146. # define S_IWRITE S_IWUSR
  147. # define S_IEXEC S_IXUSR
  148. #endif
  149. #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
  150. #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
  151. #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
  152. /* Read, write, and execute by group. */
  153. #define S_IRWXG (S_IRWXU >> 3)
  154. #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
  155. #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
  156. #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
  157. /* Read, write, and execute by others. */
  158. #define S_IRWXO (S_IRWXG >> 3)
  159. #ifdef __USE_BSD
  160. /* Macros for common mode bit masks. */
  161. # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
  162. # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
  163. # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
  164. # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
  165. #endif
  166. #ifndef __USE_FILE_OFFSET64
  167. /* Get file attributes for FILE and put them in BUF. */
  168. extern int stat (__const char *__restrict __file,
  169. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  170. /* Get file attributes for the file, device, pipe, or socket
  171. that file descriptor FD is open on and put them in BUF. */
  172. extern int fstat (int __fd, struct stat *__buf) __THROW __nonnull ((2));
  173. #else
  174. # ifdef __REDIRECT
  175. extern int __REDIRECT (stat, (__const char *__restrict __file,
  176. struct stat *__restrict __buf), stat64)
  177. __nonnull ((1, 2));
  178. extern int __REDIRECT (fstat, (int __fd, struct stat *__buf), fstat64)
  179. __nonnull ((2));
  180. # else
  181. # define stat stat64
  182. # define fstat fstat64
  183. # endif
  184. #endif
  185. #ifdef __USE_LARGEFILE64
  186. extern int stat64 (__const char *__restrict __file,
  187. struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2));
  188. extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
  189. #endif
  190. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  191. # ifndef __USE_FILE_OFFSET64
  192. /* Get file attributes about FILE and put them in BUF.
  193. If FILE is a symbolic link, do not follow it. */
  194. extern int lstat (__const char *__restrict __file,
  195. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  196. # else
  197. # ifdef __REDIRECT
  198. extern int __REDIRECT (lstat,
  199. (__const char *__restrict __file,
  200. struct stat *__restrict __buf), lstat64)
  201. __nonnull ((1, 2));
  202. # else
  203. # define lstat lstat64
  204. # endif
  205. # endif
  206. # ifdef __USE_LARGEFILE64
  207. extern int lstat64 (__const char *__restrict __file,
  208. struct stat64 *__restrict __buf)
  209. __THROW __nonnull ((1, 2));
  210. # endif
  211. #endif
  212. /* Set file access permissions for FILE to MODE.
  213. If FILE is a symbolic link, this affects its target instead. */
  214. extern int chmod (__const char *__file, __mode_t __mode)
  215. __THROW __nonnull ((1));
  216. #if 0 /* def __USE_BSD */
  217. /* Set file access permissions for FILE to MODE.
  218. If FILE is a symbolic link, this affects the link itself
  219. rather than its target. */
  220. extern int lchmod (__const char *__file, __mode_t __mode)
  221. __THROW __nonnull ((1));
  222. #endif
  223. /* Set file access permissions of the file FD is open on to MODE. */
  224. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  225. extern int fchmod (int __fd, __mode_t __mode) __THROW;
  226. #endif
  227. /* Set the file creation mask of the current process to MASK,
  228. and return the old creation mask. */
  229. extern __mode_t umask (__mode_t __mask) __THROW;
  230. #ifdef __USE_GNU
  231. /* Get the current `umask' value without changing it.
  232. This function is only available under the GNU Hurd. */
  233. extern __mode_t getumask (void) __THROW;
  234. #endif
  235. /* Create a new directory named PATH, with permission bits MODE. */
  236. extern int mkdir (__const char *__path, __mode_t __mode)
  237. __THROW __nonnull ((1));
  238. /* Create a device file named PATH, with permission and special bits MODE
  239. and device number DEV (which can be constructed from major and minor
  240. device numbers with the `makedev' macro above). */
  241. #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  242. extern int mknod (__const char *__path, __mode_t __mode, __dev_t __dev)
  243. __THROW __nonnull ((1));
  244. #endif
  245. /* Create a new FIFO named PATH, with permission bits MODE. */
  246. extern int mkfifo (__const char *__path, __mode_t __mode)
  247. __THROW __nonnull ((1));
  248. __END_DECLS
  249. #endif /* sys/stat.h */