stat.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /* Copyright (C) 1991-2016 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, see
  13. <http://www.gnu.org/licenses/>. */
  14. /*
  15. * POSIX Standard: 5.6 File Characteristics <sys/stat.h>
  16. */
  17. #ifndef _SYS_STAT_H
  18. #define _SYS_STAT_H 1
  19. #include <features.h>
  20. #include <bits/types.h> /* For __mode_t and __dev_t. */
  21. #if defined __USE_XOPEN || defined __USE_XOPEN2K || defined __USE_ATFILE
  22. # if defined __USE_XOPEN || defined __USE_XOPEN2K
  23. # define __need_time_t
  24. # endif
  25. # ifdef __USE_ATFILE
  26. # define __need_timespec
  27. # endif
  28. # include <time.h> /* For time_t resp. timespec. */
  29. #endif
  30. #if defined __USE_XOPEN || defined __USE_XOPEN2K
  31. /* The Single Unix specification says that some more types are
  32. available here. */
  33. # ifndef __dev_t_defined
  34. typedef __dev_t dev_t;
  35. # define __dev_t_defined
  36. # endif
  37. # ifndef __gid_t_defined
  38. typedef __gid_t gid_t;
  39. # define __gid_t_defined
  40. # endif
  41. # ifndef __ino_t_defined
  42. # ifndef __USE_FILE_OFFSET64
  43. typedef __ino_t ino_t;
  44. # else
  45. typedef __ino64_t ino_t;
  46. # endif
  47. # define __ino_t_defined
  48. # endif
  49. # ifndef __mode_t_defined
  50. typedef __mode_t mode_t;
  51. # define __mode_t_defined
  52. # endif
  53. # ifndef __nlink_t_defined
  54. typedef __nlink_t nlink_t;
  55. # define __nlink_t_defined
  56. # endif
  57. # ifndef __off_t_defined
  58. # ifndef __USE_FILE_OFFSET64
  59. typedef __off_t off_t;
  60. # else
  61. typedef __off64_t off_t;
  62. # endif
  63. # define __off_t_defined
  64. # endif
  65. # ifndef __uid_t_defined
  66. typedef __uid_t uid_t;
  67. # define __uid_t_defined
  68. # endif
  69. #endif /* X/Open */
  70. #ifdef __USE_UNIX98
  71. # ifndef __blkcnt_t_defined
  72. # ifndef __USE_FILE_OFFSET64
  73. typedef __blkcnt_t blkcnt_t;
  74. # else
  75. typedef __blkcnt64_t blkcnt_t;
  76. # endif
  77. # define __blkcnt_t_defined
  78. # endif
  79. # ifndef __blksize_t_defined
  80. typedef __blksize_t blksize_t;
  81. # define __blksize_t_defined
  82. # endif
  83. #endif /* Unix98 */
  84. __BEGIN_DECLS
  85. #include <bits/stat.h>
  86. #if defined __USE_MISC || defined __USE_XOPEN
  87. # define S_IFMT __S_IFMT
  88. # define S_IFDIR __S_IFDIR
  89. # define S_IFCHR __S_IFCHR
  90. # define S_IFBLK __S_IFBLK
  91. # define S_IFREG __S_IFREG
  92. # ifdef __S_IFIFO
  93. # define S_IFIFO __S_IFIFO
  94. # endif
  95. # ifdef __S_IFLNK
  96. # define S_IFLNK __S_IFLNK
  97. # endif
  98. # if (defined __USE_MISC || defined __USE_UNIX98) \
  99. && defined __S_IFSOCK
  100. # define S_IFSOCK __S_IFSOCK
  101. # endif
  102. #endif
  103. /* Test macros for file types. */
  104. #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
  105. #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
  106. #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR)
  107. #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK)
  108. #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
  109. #ifdef __S_IFIFO
  110. # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
  111. #endif
  112. #ifdef __S_IFLNK
  113. # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
  114. #endif
  115. #if defined __USE_MISC && !defined __S_IFLNK
  116. # define S_ISLNK(mode) 0
  117. #endif
  118. #if (defined __USE_UNIX98 || defined __USE_XOPEN2K) \
  119. && defined __S_IFSOCK
  120. # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
  121. #elif defined __USE_XOPEN2K
  122. # define S_ISSOCK(mode) 0
  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_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. #ifdef __USE_MISC
  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_MISC
  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. /* 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. #else
  175. # ifdef __REDIRECT_NTH
  176. extern int __REDIRECT_NTH (stat, (const char *__restrict __file,
  177. struct stat *__restrict __buf), stat64)
  178. __nonnull ((1, 2));
  179. extern int __REDIRECT_NTH (fstat, (int __fd, struct stat *__buf), fstat64)
  180. __nonnull ((2));
  181. # else
  182. # define stat stat64
  183. # define fstat fstat64
  184. # endif
  185. #endif
  186. #ifdef __USE_LARGEFILE64
  187. extern int stat64 (const char *__restrict __file,
  188. struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2));
  189. extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
  190. #endif
  191. #ifdef __USE_ATFILE
  192. /* Similar to stat, get the attributes for FILE and put them in BUF.
  193. Relative path names are interpreted relative to FD unless FD is
  194. AT_FDCWD. */
  195. # ifndef __USE_FILE_OFFSET64
  196. extern int fstatat (int __fd, const char *__restrict __file,
  197. struct stat *__restrict __buf, int __flag)
  198. __THROW __nonnull ((2, 3));
  199. # else
  200. # ifdef __REDIRECT_NTH
  201. extern int __REDIRECT_NTH (fstatat, (int __fd, const char *__restrict __file,
  202. struct stat *__restrict __buf,
  203. int __flag),
  204. fstatat64) __nonnull ((2, 3));
  205. # else
  206. # define fstatat fstatat64
  207. # endif
  208. # endif
  209. # ifdef __USE_LARGEFILE64
  210. extern int fstatat64 (int __fd, const char *__restrict __file,
  211. struct stat64 *__restrict __buf, int __flag)
  212. __THROW __nonnull ((2, 3));
  213. # endif
  214. #endif
  215. #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
  216. # ifndef __USE_FILE_OFFSET64
  217. /* Get file attributes about FILE and put them in BUF.
  218. If FILE is a symbolic link, do not follow it. */
  219. extern int lstat (const char *__restrict __file,
  220. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  221. # else
  222. # ifdef __REDIRECT_NTH
  223. extern int __REDIRECT_NTH (lstat,
  224. (const char *__restrict __file,
  225. struct stat *__restrict __buf), lstat64)
  226. __nonnull ((1, 2));
  227. # else
  228. # define lstat lstat64
  229. # endif
  230. # endif
  231. # ifdef __USE_LARGEFILE64
  232. extern int lstat64 (const char *__restrict __file,
  233. struct stat64 *__restrict __buf)
  234. __THROW __nonnull ((1, 2));
  235. # endif
  236. #endif
  237. /* Set file access permissions for FILE to MODE.
  238. If FILE is a symbolic link, this affects its target instead. */
  239. extern int chmod (const char *__file, __mode_t __mode)
  240. __THROW __nonnull ((1));
  241. #ifdef __USE_MISC
  242. /* Set file access permissions for FILE to MODE.
  243. If FILE is a symbolic link, this affects the link itself
  244. rather than its target. */
  245. extern int lchmod (const char *__file, __mode_t __mode)
  246. __THROW __nonnull ((1));
  247. #endif
  248. /* Set file access permissions of the file FD is open on to MODE. */
  249. #ifdef __USE_POSIX
  250. extern int fchmod (int __fd, __mode_t __mode) __THROW;
  251. #endif
  252. #ifdef __USE_ATFILE
  253. /* Set file access permissions of FILE relative to
  254. the directory FD is open on. */
  255. extern int fchmodat (int __fd, const char *__file, __mode_t __mode,
  256. int __flag)
  257. __THROW __nonnull ((2)) __wur;
  258. #endif /* Use ATFILE. */
  259. /* Set the file creation mask of the current process to MASK,
  260. and return the old creation mask. */
  261. extern __mode_t umask (__mode_t __mask) __THROW;
  262. #ifdef __USE_GNU
  263. /* Get the current `umask' value without changing it.
  264. This function is only available under the GNU Hurd. */
  265. extern __mode_t getumask (void) __THROW;
  266. #endif
  267. /* Create a new directory named PATH, with permission bits MODE. */
  268. extern int mkdir (const char *__path, __mode_t __mode)
  269. __THROW __nonnull ((1));
  270. #ifdef __USE_ATFILE
  271. /* Like mkdir, create a new directory with permission bits MODE. But
  272. interpret relative PATH names relative to the directory associated
  273. with FD. */
  274. extern int mkdirat (int __fd, const char *__path, __mode_t __mode)
  275. __THROW __nonnull ((2));
  276. #endif
  277. /* Create a device file named PATH, with permission and special bits MODE
  278. and device number DEV (which can be constructed from major and minor
  279. device numbers with the `makedev' macro above). */
  280. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  281. extern int mknod (const char *__path, __mode_t __mode, __dev_t __dev)
  282. __THROW __nonnull ((1));
  283. # ifdef __USE_ATFILE
  284. /* Like mknod, create a new device file with permission bits MODE and
  285. device number DEV. But interpret relative PATH names relative to
  286. the directory associated with FD. */
  287. extern int mknodat (int __fd, const char *__path, __mode_t __mode,
  288. __dev_t __dev) __THROW __nonnull ((2));
  289. # endif
  290. #endif
  291. /* Create a new FIFO named PATH, with permission bits MODE. */
  292. extern int mkfifo (const char *__path, __mode_t __mode)
  293. __THROW __nonnull ((1));
  294. #ifdef __USE_ATFILE
  295. /* Like mkfifo, create a new FIFO with permission bits MODE. But
  296. interpret relative PATH names relative to the directory associated
  297. with FD. */
  298. extern int mkfifoat (int __fd, const char *__path, __mode_t __mode)
  299. __THROW __nonnull ((2));
  300. #endif
  301. #ifdef __USE_ATFILE
  302. /* Set file access and modification times relative to directory file
  303. descriptor. */
  304. extern int utimensat (int __fd, const char *__path,
  305. const struct timespec __times[2],
  306. int __flags)
  307. __THROW __nonnull ((2));
  308. #endif
  309. #ifdef __USE_XOPEN2K8
  310. /* Set file access and modification times of the file associated with FD. */
  311. extern int futimens (int __fd, const struct timespec __times[2]) __THROW;
  312. #endif
  313. /* To allow the `struct stat' structure and the file type `mode_t'
  314. bits to vary without changing shared library major version number,
  315. the `stat' family of functions and `mknod' are in fact inline
  316. wrappers around calls to `xstat', `fxstat', `lxstat', and `xmknod',
  317. which all take a leading version-number argument designating the
  318. data structure and bits used. <bits/stat.h> defines _STAT_VER with
  319. the version number corresponding to `struct stat' as defined in
  320. that file; and _MKNOD_VER with the version number corresponding to
  321. the S_IF* macros defined therein. It is arranged that when not
  322. inlined these function are always statically linked; that way a
  323. dynamically-linked executable always encodes the version number
  324. corresponding to the data structures it uses, so the `x' functions
  325. in the shared library can adapt without needing to recompile all
  326. callers. */
  327. #ifndef _STAT_VER
  328. # define _STAT_VER 0
  329. #endif
  330. #ifndef _MKNOD_VER
  331. # define _MKNOD_VER 0
  332. #endif
  333. /* Wrappers for stat and mknod system calls. */
  334. #ifndef __USE_FILE_OFFSET64
  335. extern int __fxstat (int __ver, int __fildes, struct stat *__stat_buf)
  336. __THROW __nonnull ((3));
  337. extern int __xstat (int __ver, const char *__filename,
  338. struct stat *__stat_buf) __THROW __nonnull ((2, 3));
  339. extern int __lxstat (int __ver, const char *__filename,
  340. struct stat *__stat_buf) __THROW __nonnull ((2, 3));
  341. extern int __fxstatat (int __ver, int __fildes, const char *__filename,
  342. struct stat *__stat_buf, int __flag)
  343. __THROW __nonnull ((3, 4));
  344. #else
  345. # ifdef __REDIRECT_NTH
  346. extern int __REDIRECT_NTH (__fxstat, (int __ver, int __fildes,
  347. struct stat *__stat_buf), __fxstat64)
  348. __nonnull ((3));
  349. extern int __REDIRECT_NTH (__xstat, (int __ver, const char *__filename,
  350. struct stat *__stat_buf), __xstat64)
  351. __nonnull ((2, 3));
  352. extern int __REDIRECT_NTH (__lxstat, (int __ver, const char *__filename,
  353. struct stat *__stat_buf), __lxstat64)
  354. __nonnull ((2, 3));
  355. extern int __REDIRECT_NTH (__fxstatat, (int __ver, int __fildes,
  356. const char *__filename,
  357. struct stat *__stat_buf, int __flag),
  358. __fxstatat64) __nonnull ((3, 4));
  359. # else
  360. # define __fxstat __fxstat64
  361. # define __xstat __xstat64
  362. # define __lxstat __lxstat64
  363. # endif
  364. #endif
  365. #ifdef __USE_LARGEFILE64
  366. extern int __fxstat64 (int __ver, int __fildes, struct stat64 *__stat_buf)
  367. __THROW __nonnull ((3));
  368. extern int __xstat64 (int __ver, const char *__filename,
  369. struct stat64 *__stat_buf) __THROW __nonnull ((2, 3));
  370. extern int __lxstat64 (int __ver, const char *__filename,
  371. struct stat64 *__stat_buf) __THROW __nonnull ((2, 3));
  372. extern int __fxstatat64 (int __ver, int __fildes, const char *__filename,
  373. struct stat64 *__stat_buf, int __flag)
  374. __THROW __nonnull ((3, 4));
  375. #endif
  376. extern int __xmknod (int __ver, const char *__path, __mode_t __mode,
  377. __dev_t *__dev) __THROW __nonnull ((2, 4));
  378. extern int __xmknodat (int __ver, int __fd, const char *__path,
  379. __mode_t __mode, __dev_t *__dev)
  380. __THROW __nonnull ((3, 5));
  381. #ifdef __USE_EXTERN_INLINES
  382. /* Inlined versions of the real stat and mknod functions. */
  383. __extern_inline int
  384. __NTH (stat (const char *__path, struct stat *__statbuf))
  385. {
  386. return __xstat (_STAT_VER, __path, __statbuf);
  387. }
  388. # if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  389. __extern_inline int
  390. __NTH (lstat (const char *__path, struct stat *__statbuf))
  391. {
  392. return __lxstat (_STAT_VER, __path, __statbuf);
  393. }
  394. # endif
  395. __extern_inline int
  396. __NTH (fstat (int __fd, struct stat *__statbuf))
  397. {
  398. return __fxstat (_STAT_VER, __fd, __statbuf);
  399. }
  400. # ifdef __USE_ATFILE
  401. __extern_inline int
  402. __NTH (fstatat (int __fd, const char *__filename, struct stat *__statbuf,
  403. int __flag))
  404. {
  405. return __fxstatat (_STAT_VER, __fd, __filename, __statbuf, __flag);
  406. }
  407. # endif
  408. # ifdef __USE_MISC
  409. __extern_inline int
  410. __NTH (mknod (const char *__path, __mode_t __mode, __dev_t __dev))
  411. {
  412. return __xmknod (_MKNOD_VER, __path, __mode, &__dev);
  413. }
  414. # endif
  415. # ifdef __USE_ATFILE
  416. __extern_inline int
  417. __NTH (mknodat (int __fd, const char *__path, __mode_t __mode,
  418. __dev_t __dev))
  419. {
  420. return __xmknodat (_MKNOD_VER, __fd, __path, __mode, &__dev);
  421. }
  422. # endif
  423. # if defined __USE_LARGEFILE64 \
  424. && (! defined __USE_FILE_OFFSET64 \
  425. || (defined __REDIRECT_NTH && defined __OPTIMIZE__))
  426. __extern_inline int
  427. __NTH (stat64 (const char *__path, struct stat64 *__statbuf))
  428. {
  429. return __xstat64 (_STAT_VER, __path, __statbuf);
  430. }
  431. # if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  432. __extern_inline int
  433. __NTH (lstat64 (const char *__path, struct stat64 *__statbuf))
  434. {
  435. return __lxstat64 (_STAT_VER, __path, __statbuf);
  436. }
  437. # endif
  438. __extern_inline int
  439. __NTH (fstat64 (int __fd, struct stat64 *__statbuf))
  440. {
  441. return __fxstat64 (_STAT_VER, __fd, __statbuf);
  442. }
  443. # ifdef __USE_ATFILE
  444. __extern_inline int
  445. __NTH (fstatat64 (int __fd, const char *__filename, struct stat64 *__statbuf,
  446. int __flag))
  447. {
  448. return __fxstatat64 (_STAT_VER, __fd, __filename, __statbuf, __flag);
  449. }
  450. # endif
  451. # endif
  452. #endif
  453. __END_DECLS
  454. #endif /* sys/stat.h */