stat.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 || defined __USE_XOPEN2K8
  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 __USE_XOPEN2K) \
  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 || defined __USE_XOPEN2K) \
  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. libc_hidden_proto(fstatat)
  205. # else
  206. # ifdef __REDIRECT_NTH
  207. extern int __REDIRECT_NTH (fstatat, (int __fd, const char *__restrict __file,
  208. struct stat *__restrict __buf,
  209. int __flag),
  210. fstatat64) __nonnull ((2, 3));
  211. # else
  212. # define fstatat fstatat64
  213. # endif
  214. # endif
  215. # ifdef __USE_LARGEFILE64
  216. extern int fstatat64 (int __fd, const char *__restrict __file,
  217. struct stat64 *__restrict __buf, int __flag)
  218. __THROW __nonnull ((2, 3));
  219. libc_hidden_proto(fstatat64)
  220. # endif
  221. #endif
  222. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
  223. # ifndef __USE_FILE_OFFSET64
  224. /* Get file attributes about FILE and put them in BUF.
  225. If FILE is a symbolic link, do not follow it. */
  226. extern int lstat (const char *__restrict __file,
  227. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  228. libc_hidden_proto(lstat)
  229. # else
  230. # ifdef __REDIRECT_NTH
  231. extern int __REDIRECT_NTH (lstat,
  232. (const char *__restrict __file,
  233. struct stat *__restrict __buf), lstat64)
  234. __nonnull ((1, 2));
  235. # else
  236. # define lstat lstat64
  237. # endif
  238. # endif
  239. # ifdef __USE_LARGEFILE64
  240. extern int lstat64 (const char *__restrict __file,
  241. struct stat64 *__restrict __buf)
  242. __THROW __nonnull ((1, 2));
  243. libc_hidden_proto(lstat64)
  244. # endif
  245. #endif
  246. /* Set file access permissions for FILE to MODE.
  247. If FILE is a symbolic link, this affects its target instead. */
  248. extern int chmod (const char *__file, __mode_t __mode)
  249. __THROW __nonnull ((1));
  250. libc_hidden_proto(chmod)
  251. #if 0 /*def __USE_BSD*/
  252. /* Set file access permissions for FILE to MODE.
  253. If FILE is a symbolic link, this affects the link itself
  254. rather than its target. */
  255. extern int lchmod (const char *__file, __mode_t __mode)
  256. __THROW __nonnull ((1));
  257. #endif
  258. /* Set file access permissions of the file FD is open on to MODE. */
  259. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
  260. extern int fchmod (int __fd, __mode_t __mode) __THROW;
  261. #endif
  262. #ifdef __USE_ATFILE
  263. /* Set file access permissions of FILE relative to
  264. the directory FD is open on. */
  265. extern int fchmodat (int __fd, const char *__file, __mode_t __mode,
  266. int __flag)
  267. __THROW __nonnull ((2)) __wur;
  268. libc_hidden_proto(fchmodat)
  269. #endif /* Use ATFILE. */
  270. /* Set the file creation mask of the current process to MASK,
  271. and return the old creation mask. */
  272. extern __mode_t umask (__mode_t __mask) __THROW;
  273. #if 0 /*def __USE_GNU*/
  274. /* Get the current `umask' value without changing it.
  275. This function is only available under the GNU Hurd. */
  276. extern __mode_t getumask (void) __THROW;
  277. #endif
  278. /* Create a new directory named PATH, with permission bits MODE. */
  279. extern int mkdir (const char *__path, __mode_t __mode)
  280. __THROW __nonnull ((1));
  281. libc_hidden_proto(mkdir)
  282. #ifdef __USE_ATFILE
  283. /* Like mkdir, create a new directory with permission bits MODE. But
  284. interpret relative PATH names relative to the directory associated
  285. with FD. */
  286. extern int mkdirat (int __fd, const char *__path, __mode_t __mode)
  287. __THROW __nonnull ((2));
  288. libc_hidden_proto(mkdirat)
  289. #endif
  290. /* Create a device file named PATH, with permission and special bits MODE
  291. and device number DEV (which can be constructed from major and minor
  292. device numbers with the `makedev' macro above). */
  293. #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  294. extern int mknod (const char *__path, __mode_t __mode, __dev_t __dev)
  295. __THROW __nonnull ((1));
  296. libc_hidden_proto(mknod)
  297. # ifdef __USE_ATFILE
  298. /* Like mknod, create a new device file with permission bits MODE and
  299. device number DEV. But interpret relative PATH names relative to
  300. the directory associated with FD. */
  301. extern int mknodat (int __fd, const char *__path, __mode_t __mode,
  302. __dev_t __dev) __THROW __nonnull ((2));
  303. libc_hidden_proto(mknodat)
  304. # endif
  305. #endif
  306. /* Create a new FIFO named PATH, with permission bits MODE. */
  307. extern int mkfifo (const char *__path, __mode_t __mode)
  308. __THROW __nonnull ((1));
  309. #ifdef __USE_ATFILE
  310. /* Like mkfifo, create a new FIFO with permission bits MODE. But
  311. interpret relative PATH names relative to the directory associated
  312. with FD. */
  313. extern int mkfifoat (int __fd, const char *__path, __mode_t __mode)
  314. __THROW __nonnull ((2));
  315. #endif
  316. #ifdef __USE_ATFILE
  317. /* Set file access and modification times relative to directory file
  318. descriptor. */
  319. extern int utimensat (int __fd, const char *__path,
  320. const struct timespec __times[2],
  321. int __flags)
  322. __THROW __nonnull ((2));
  323. libc_hidden_proto(utimensat)
  324. #endif
  325. #ifdef __USE_XOPEN2K8
  326. /* Set file access and modification times of the file associated with FD. */
  327. extern int futimens (int __fd, const struct timespec __times[2]) __THROW;
  328. #endif
  329. /* on uClibc we have unversioned struct stat and mknod.
  330. * bits/stat.h is filled with wrong info, so we undo it here. */
  331. #undef _STAT_VER
  332. #define _STAT_VER 0
  333. #undef _MKNOD_VER
  334. #define _MKNOD_VER 0
  335. #ifdef __UCLIBC_HAVE_STATX__
  336. #ifdef __USE_GNU
  337. # include <bits/statx.h>
  338. #endif
  339. #endif
  340. __END_DECLS
  341. #endif /* sys/stat.h */