stat.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /* Copyright (C) 1991,1992,1995-2004,2005,2006 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. libc_hidden_proto(stat)
  171. /* Get file attributes for the file, device, pipe, or socket
  172. that file descriptor FD is open on and put them in BUF. */
  173. extern int fstat (int __fd, struct stat *__buf) __THROW __nonnull ((2));
  174. libc_hidden_proto(fstat)
  175. #else
  176. # ifdef __REDIRECT_NTH
  177. extern int __REDIRECT_NTH (stat, (__const char *__restrict __file,
  178. struct stat *__restrict __buf), stat64)
  179. __nonnull ((1, 2));
  180. extern int __REDIRECT_NTH (fstat, (int __fd, struct stat *__buf), fstat64)
  181. __nonnull ((2));
  182. # else
  183. # define stat stat64
  184. # define fstat fstat64
  185. # endif
  186. #endif
  187. #ifdef __USE_LARGEFILE64
  188. extern int stat64 (__const char *__restrict __file,
  189. struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2));
  190. extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
  191. libc_hidden_proto(stat64)
  192. libc_hidden_proto(fstat64)
  193. #endif
  194. #ifdef __USE_ATFILE
  195. /* Similar to stat, get the attributes for FILE and put them in BUF.
  196. Relative path names are interpreted relative to FD unless FD is
  197. AT_FDCWD. */
  198. # ifndef __USE_FILE_OFFSET64
  199. extern int fstatat (int __fd, __const char *__restrict __file,
  200. struct stat *__restrict __buf, int __flag)
  201. __THROW __nonnull ((2, 3));
  202. # else
  203. # ifdef __REDIRECT_NTH
  204. extern int __REDIRECT_NTH (fstatat, (int __fd, __const char *__restrict __file,
  205. struct stat *__restrict __buf,
  206. int __flag),
  207. fstatat64) __nonnull ((2, 3));
  208. # else
  209. # define fstatat fstatat64
  210. # endif
  211. # endif
  212. extern int fstatat64 (int __fd, __const char *__restrict __file,
  213. struct stat64 *__restrict __buf, int __flag)
  214. __THROW __nonnull ((2, 3));
  215. #endif
  216. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  217. # ifndef __USE_FILE_OFFSET64
  218. /* Get file attributes about FILE and put them in BUF.
  219. If FILE is a symbolic link, do not follow it. */
  220. extern int lstat (__const char *__restrict __file,
  221. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  222. libc_hidden_proto(lstat)
  223. # else
  224. # ifdef __REDIRECT_NTH
  225. extern int __REDIRECT_NTH (lstat,
  226. (__const char *__restrict __file,
  227. struct stat *__restrict __buf), lstat64)
  228. __nonnull ((1, 2));
  229. # else
  230. # define lstat lstat64
  231. # endif
  232. # endif
  233. # ifdef __USE_LARGEFILE64
  234. extern int lstat64 (__const char *__restrict __file,
  235. struct stat64 *__restrict __buf)
  236. __THROW __nonnull ((1, 2));
  237. libc_hidden_proto(lstat64)
  238. # endif
  239. #endif
  240. /* Set file access permissions for FILE to MODE.
  241. If FILE is a symbolic link, this affects its target instead. */
  242. extern int chmod (__const char *__file, __mode_t __mode)
  243. __THROW __nonnull ((1));
  244. libc_hidden_proto(chmod)
  245. #if 0 /*def __USE_BSD*/
  246. /* Set file access permissions for FILE to MODE.
  247. If FILE is a symbolic link, this affects the link itself
  248. rather than its target. */
  249. extern int lchmod (__const char *__file, __mode_t __mode)
  250. __THROW __nonnull ((1));
  251. #endif
  252. /* Set file access permissions of the file FD is open on to MODE. */
  253. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  254. extern int fchmod (int __fd, __mode_t __mode) __THROW;
  255. #endif
  256. #ifdef __USE_ATFILE
  257. /* Set file access permissions of FILE relative to
  258. the directory FD is open on. */
  259. extern int fchmodat (int __fd, __const char *__file, __mode_t mode, int __flag)
  260. __THROW __nonnull ((2)) __wur;
  261. #endif /* Use ATFILE. */
  262. /* Set the file creation mask of the current process to MASK,
  263. and return the old creation mask. */
  264. extern __mode_t umask (__mode_t __mask) __THROW;
  265. #if 0 /*def __USE_GNU*/
  266. /* Get the current `umask' value without changing it.
  267. This function is only available under the GNU Hurd. */
  268. extern __mode_t getumask (void) __THROW;
  269. #endif
  270. /* Create a new directory named PATH, with permission bits MODE. */
  271. extern int mkdir (__const char *__path, __mode_t __mode)
  272. __THROW __nonnull ((1));
  273. libc_hidden_proto(mkdir)
  274. #ifdef __USE_ATFILE
  275. /* Like mkdir, create a new directory with permission bits MODE. But
  276. interpret relative PATH names relative to the directory associated
  277. with FD. */
  278. extern int mkdirat (int __fd, __const char *__path, __mode_t __mode)
  279. __THROW __nonnull ((2));
  280. #endif
  281. /* Create a device file named PATH, with permission and special bits MODE
  282. and device number DEV (which can be constructed from major and minor
  283. device numbers with the `makedev' macro above). */
  284. #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  285. extern int mknod (__const char *__path, __mode_t __mode, __dev_t __dev)
  286. __THROW __nonnull ((1));
  287. libc_hidden_proto(mknod)
  288. #endif
  289. #ifdef __USE_ATFILE
  290. /* Like mknod, create a new device file with permission bits MODE and
  291. device number DEV. But interpret relative PATH names relative to
  292. the directory associated with FD. */
  293. extern int mknodat (int __fd, __const char *__path, __mode_t __mode,
  294. __dev_t __dev) __THROW __nonnull ((2));
  295. #endif
  296. /* Create a new FIFO named PATH, with permission bits MODE. */
  297. extern int mkfifo (__const char *__path, __mode_t __mode)
  298. __THROW __nonnull ((1));
  299. #ifdef __USE_ATFILE
  300. /* Like mkfifo, create a new FIFO with permission bits MODE. But
  301. interpret relative PATH names relative to the directory associated
  302. with FD. */
  303. extern int mkfifoat (int __fd, __const char *__path, __mode_t __mode)
  304. __THROW __nonnull ((2));
  305. #endif
  306. /* on uClibc we have unversioned struct stat and mknod.
  307. * bits/stat.h is filled with wrong info, so we undo it here. */
  308. #undef _STAT_VER
  309. #define _STAT_VER 0
  310. #undef _MKNOD_VER
  311. #define _MKNOD_VER 0
  312. __END_DECLS
  313. #endif /* sys/stat.h */