stat.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /* Copyright (C) 1991, 1992, 1995-2004, 2005, 2006, 2007, 2009
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. /*
  17. * POSIX Standard: 5.6 File Characteristics <sys/stat.h>
  18. */
  19. #ifndef _SYS_STAT_H
  20. #define _SYS_STAT_H 1
  21. #include <features.h>
  22. #include <bits/types.h> /* For __mode_t and __dev_t. */
  23. #if defined __USE_XOPEN || defined __USE_XOPEN2K || defined __USE_MISC \
  24. || defined __USE_ATFILE
  25. # if defined __USE_XOPEN || defined __USE_XOPEN2K
  26. # define __need_time_t
  27. # endif
  28. # if defined __USE_MISC || defined __USE_ATFILE
  29. # define __need_timespec
  30. # endif
  31. # include <time.h> /* For time_t resp. timespec. */
  32. #endif
  33. #if defined __USE_XOPEN || defined __USE_XOPEN2K
  34. /* The Single Unix specification says that some more types are
  35. available here. */
  36. # ifndef __dev_t_defined
  37. typedef __dev_t dev_t;
  38. # define __dev_t_defined
  39. # endif
  40. # ifndef __gid_t_defined
  41. typedef __gid_t gid_t;
  42. # define __gid_t_defined
  43. # endif
  44. # ifndef __ino_t_defined
  45. # ifndef __USE_FILE_OFFSET64
  46. typedef __ino_t ino_t;
  47. # else
  48. typedef __ino64_t ino_t;
  49. # endif
  50. # define __ino_t_defined
  51. # endif
  52. # ifndef __mode_t_defined
  53. typedef __mode_t mode_t;
  54. # define __mode_t_defined
  55. # endif
  56. # ifndef __nlink_t_defined
  57. typedef __nlink_t nlink_t;
  58. # define __nlink_t_defined
  59. # endif
  60. # ifndef __off_t_defined
  61. # ifndef __USE_FILE_OFFSET64
  62. typedef __off_t off_t;
  63. # else
  64. typedef __off64_t off_t;
  65. # endif
  66. # define __off_t_defined
  67. # endif
  68. # ifndef __uid_t_defined
  69. typedef __uid_t uid_t;
  70. # define __uid_t_defined
  71. # endif
  72. #endif /* X/Open */
  73. #ifdef __USE_UNIX98
  74. # ifndef __blkcnt_t_defined
  75. # ifndef __USE_FILE_OFFSET64
  76. typedef __blkcnt_t blkcnt_t;
  77. # else
  78. typedef __blkcnt64_t blkcnt_t;
  79. # endif
  80. # define __blkcnt_t_defined
  81. # endif
  82. # ifndef __blksize_t_defined
  83. typedef __blksize_t blksize_t;
  84. # define __blksize_t_defined
  85. # endif
  86. #endif /* Unix98 */
  87. __BEGIN_DECLS
  88. #include <bits/stat.h>
  89. #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
  90. # define S_IFMT __S_IFMT
  91. # define S_IFDIR __S_IFDIR
  92. # define S_IFCHR __S_IFCHR
  93. # define S_IFBLK __S_IFBLK
  94. # define S_IFREG __S_IFREG
  95. # ifdef __S_IFIFO
  96. # define S_IFIFO __S_IFIFO
  97. # endif
  98. # ifdef __S_IFLNK
  99. # define S_IFLNK __S_IFLNK
  100. # endif
  101. # if (defined __USE_BSD || defined __USE_MISC || defined __USE_UNIX98) \
  102. && defined __S_IFSOCK
  103. # define S_IFSOCK __S_IFSOCK
  104. # endif
  105. #endif
  106. /* Test macros for file types. */
  107. #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
  108. #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
  109. #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR)
  110. #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK)
  111. #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
  112. #ifdef __S_IFIFO
  113. # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
  114. #endif
  115. #ifdef __S_IFLNK
  116. # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
  117. #endif
  118. #if defined __USE_BSD && !defined __S_IFLNK
  119. # define S_ISLNK(mode) 0
  120. #endif
  121. #if (defined __USE_BSD || defined __USE_UNIX98) \
  122. && defined __S_IFSOCK
  123. # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
  124. #endif
  125. /* These are from POSIX.1b. If the objects are not implemented using separate
  126. distinct file types, the macros always will evaluate to zero. Unlike the
  127. other S_* macros the following three take a pointer to a `struct stat'
  128. object as the argument. */
  129. #ifdef __USE_POSIX199309
  130. # define S_TYPEISMQ(buf) __S_TYPEISMQ(buf)
  131. # define S_TYPEISSEM(buf) __S_TYPEISSEM(buf)
  132. # define S_TYPEISSHM(buf) __S_TYPEISSHM(buf)
  133. #endif
  134. /* Protection bits. */
  135. #define S_ISUID __S_ISUID /* Set user ID on execution. */
  136. #define S_ISGID __S_ISGID /* Set group ID on execution. */
  137. #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
  138. /* Save swapped text after use (sticky bit). This is pretty well obsolete. */
  139. # define S_ISVTX __S_ISVTX
  140. #endif
  141. #define S_IRUSR __S_IREAD /* Read by owner. */
  142. #define S_IWUSR __S_IWRITE /* Write by owner. */
  143. #define S_IXUSR __S_IEXEC /* Execute by owner. */
  144. /* Read, write, and execute by owner. */
  145. #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
  146. #if defined __USE_MISC && defined __USE_BSD
  147. # define S_IREAD S_IRUSR
  148. # define S_IWRITE S_IWUSR
  149. # define S_IEXEC S_IXUSR
  150. #endif
  151. #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
  152. #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
  153. #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
  154. /* Read, write, and execute by group. */
  155. #define S_IRWXG (S_IRWXU >> 3)
  156. #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
  157. #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
  158. #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
  159. /* Read, write, and execute by others. */
  160. #define S_IRWXO (S_IRWXG >> 3)
  161. #ifdef __USE_BSD
  162. /* Macros for common mode bit masks. */
  163. # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
  164. # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
  165. # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
  166. # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
  167. #endif
  168. #ifndef __USE_FILE_OFFSET64
  169. /* Get file attributes for FILE and put them in BUF. */
  170. extern int stat (__const char *__restrict __file,
  171. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  172. libc_hidden_proto(stat)
  173. /* Get file attributes for the file, device, pipe, or socket
  174. that file descriptor FD is open on and put them in BUF. */
  175. extern int fstat (int __fd, struct stat *__buf) __THROW __nonnull ((2));
  176. libc_hidden_proto(fstat)
  177. #else
  178. # ifdef __REDIRECT_NTH
  179. extern int __REDIRECT_NTH (stat, (__const char *__restrict __file,
  180. struct stat *__restrict __buf), stat64)
  181. __nonnull ((1, 2));
  182. extern int __REDIRECT_NTH (fstat, (int __fd, struct stat *__buf), fstat64)
  183. __nonnull ((2));
  184. # else
  185. # define stat stat64
  186. # define fstat fstat64
  187. # endif
  188. #endif
  189. #ifdef __USE_LARGEFILE64
  190. extern int stat64 (__const char *__restrict __file,
  191. struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2));
  192. extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
  193. libc_hidden_proto(stat64)
  194. libc_hidden_proto(fstat64)
  195. #endif
  196. #ifdef __USE_ATFILE
  197. /* Similar to stat, get the attributes for FILE and put them in BUF.
  198. Relative path names are interpreted relative to FD unless FD is
  199. AT_FDCWD. */
  200. # ifndef __USE_FILE_OFFSET64
  201. extern int fstatat (int __fd, __const char *__restrict __file,
  202. struct stat *__restrict __buf, int __flag)
  203. __THROW __nonnull ((2, 3));
  204. # else
  205. # ifdef __REDIRECT_NTH
  206. extern int __REDIRECT_NTH (fstatat, (int __fd, __const char *__restrict __file,
  207. struct stat *__restrict __buf,
  208. int __flag),
  209. fstatat64) __nonnull ((2, 3));
  210. # else
  211. # define fstatat fstatat64
  212. # endif
  213. # endif
  214. # ifdef __USE_LARGEFILE64
  215. extern int fstatat64 (int __fd, __const char *__restrict __file,
  216. struct stat64 *__restrict __buf, int __flag)
  217. __THROW __nonnull ((2, 3));
  218. # endif
  219. #endif
  220. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
  221. # ifndef __USE_FILE_OFFSET64
  222. /* Get file attributes about FILE and put them in BUF.
  223. If FILE is a symbolic link, do not follow it. */
  224. extern int lstat (__const char *__restrict __file,
  225. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  226. libc_hidden_proto(lstat)
  227. # else
  228. # ifdef __REDIRECT_NTH
  229. extern int __REDIRECT_NTH (lstat,
  230. (__const char *__restrict __file,
  231. struct stat *__restrict __buf), lstat64)
  232. __nonnull ((1, 2));
  233. # else
  234. # define lstat lstat64
  235. # endif
  236. # endif
  237. # ifdef __USE_LARGEFILE64
  238. extern int lstat64 (__const char *__restrict __file,
  239. struct stat64 *__restrict __buf)
  240. __THROW __nonnull ((1, 2));
  241. libc_hidden_proto(lstat64)
  242. # endif
  243. #endif
  244. /* Set file access permissions for FILE to MODE.
  245. If FILE is a symbolic link, this affects its target instead. */
  246. extern int chmod (__const char *__file, __mode_t __mode)
  247. __THROW __nonnull ((1));
  248. libc_hidden_proto(chmod)
  249. #if 0 /*def __USE_BSD*/
  250. /* Set file access permissions for FILE to MODE.
  251. If FILE is a symbolic link, this affects the link itself
  252. rather than its target. */
  253. extern int lchmod (__const char *__file, __mode_t __mode)
  254. __THROW __nonnull ((1));
  255. #endif
  256. /* Set file access permissions of the file FD is open on to MODE. */
  257. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  258. extern int fchmod (int __fd, __mode_t __mode) __THROW;
  259. #endif
  260. #ifdef __USE_ATFILE
  261. /* Set file access permissions of FILE relative to
  262. the directory FD is open on. */
  263. extern int fchmodat (int __fd, __const char *__file, __mode_t __mode,
  264. int __flag)
  265. __THROW __nonnull ((2)) __wur;
  266. #endif /* Use ATFILE. */
  267. /* Set the file creation mask of the current process to MASK,
  268. and return the old creation mask. */
  269. extern __mode_t umask (__mode_t __mask) __THROW;
  270. #if 0 /*def __USE_GNU*/
  271. /* Get the current `umask' value without changing it.
  272. This function is only available under the GNU Hurd. */
  273. extern __mode_t getumask (void) __THROW;
  274. #endif
  275. /* Create a new directory named PATH, with permission bits MODE. */
  276. extern int mkdir (__const char *__path, __mode_t __mode)
  277. __THROW __nonnull ((1));
  278. libc_hidden_proto(mkdir)
  279. #ifdef __USE_ATFILE
  280. /* Like mkdir, create a new directory with permission bits MODE. But
  281. interpret relative PATH names relative to the directory associated
  282. with FD. */
  283. extern int mkdirat (int __fd, __const char *__path, __mode_t __mode)
  284. __THROW __nonnull ((2));
  285. #endif
  286. /* Create a device file named PATH, with permission and special bits MODE
  287. and device number DEV (which can be constructed from major and minor
  288. device numbers with the `makedev' macro above). */
  289. #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  290. extern int mknod (__const char *__path, __mode_t __mode, __dev_t __dev)
  291. __THROW __nonnull ((1));
  292. libc_hidden_proto(mknod)
  293. # ifdef __USE_ATFILE
  294. /* Like mknod, create a new device file with permission bits MODE and
  295. device number DEV. But interpret relative PATH names relative to
  296. the directory associated with FD. */
  297. extern int mknodat (int __fd, __const char *__path, __mode_t __mode,
  298. __dev_t __dev) __THROW __nonnull ((2));
  299. libc_hidden_proto(mknodat)
  300. # endif
  301. #endif
  302. /* Create a new FIFO named PATH, with permission bits MODE. */
  303. extern int mkfifo (__const char *__path, __mode_t __mode)
  304. __THROW __nonnull ((1));
  305. #ifdef __USE_ATFILE
  306. /* Like mkfifo, create a new FIFO with permission bits MODE. But
  307. interpret relative PATH names relative to the directory associated
  308. with FD. */
  309. extern int mkfifoat (int __fd, __const char *__path, __mode_t __mode)
  310. __THROW __nonnull ((2));
  311. #endif
  312. #ifdef __USE_ATFILE
  313. /* Set file access and modification times relative to directory file
  314. descriptor. */
  315. extern int utimensat (int __fd, __const char *__path,
  316. __const struct timespec __times[2],
  317. int __flags)
  318. __THROW __nonnull ((2));
  319. libc_hidden_proto(utimensat)
  320. #endif
  321. #ifdef __USE_XOPEN2K8
  322. /* Set file access and modification times of the file associated with FD. */
  323. extern int futimens (int __fd, __const struct timespec __times[2]) __THROW;
  324. #endif
  325. /* on uClibc we have unversioned struct stat and mknod.
  326. * bits/stat.h is filled with wrong info, so we undo it here. */
  327. #undef _STAT_VER
  328. #define _STAT_VER 0
  329. #undef _MKNOD_VER
  330. #define _MKNOD_VER 0
  331. __END_DECLS
  332. #endif /* sys/stat.h */