stat.h 12 KB

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