stat.h 12 KB

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