stat.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. /* Copyright (C) 1991, 1992, 1995-2004, 2005, 2006, 2007, 2009, 2010
  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 || defined __USE_XOPEN2K) \
  122. && defined __S_IFSOCK
  123. # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
  124. #elif defined __USE_XOPEN2K
  125. # define S_ISSOCK(mode) 0
  126. #endif
  127. /* These are from POSIX.1b. If the objects are not implemented using separate
  128. distinct file types, the macros always will evaluate to zero. Unlike the
  129. other S_* macros the following three take a pointer to a `struct stat'
  130. object as the argument. */
  131. #ifdef __USE_POSIX199309
  132. # define S_TYPEISMQ(buf) __S_TYPEISMQ(buf)
  133. # define S_TYPEISSEM(buf) __S_TYPEISSEM(buf)
  134. # define S_TYPEISSHM(buf) __S_TYPEISSHM(buf)
  135. #endif
  136. /* Protection bits. */
  137. #define S_ISUID __S_ISUID /* Set user ID on execution. */
  138. #define S_ISGID __S_ISGID /* Set group ID on execution. */
  139. #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
  140. /* Save swapped text after use (sticky bit). This is pretty well obsolete. */
  141. # define S_ISVTX __S_ISVTX
  142. #endif
  143. #define S_IRUSR __S_IREAD /* Read by owner. */
  144. #define S_IWUSR __S_IWRITE /* Write by owner. */
  145. #define S_IXUSR __S_IEXEC /* Execute by owner. */
  146. /* Read, write, and execute by owner. */
  147. #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
  148. #if defined __USE_MISC && defined __USE_BSD
  149. # define S_IREAD S_IRUSR
  150. # define S_IWRITE S_IWUSR
  151. # define S_IEXEC S_IXUSR
  152. #endif
  153. #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
  154. #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
  155. #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
  156. /* Read, write, and execute by group. */
  157. #define S_IRWXG (S_IRWXU >> 3)
  158. #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
  159. #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
  160. #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
  161. /* Read, write, and execute by others. */
  162. #define S_IRWXO (S_IRWXG >> 3)
  163. #ifdef __USE_BSD
  164. /* Macros for common mode bit masks. */
  165. # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
  166. # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
  167. # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
  168. # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
  169. #endif
  170. #ifndef __USE_FILE_OFFSET64
  171. /* Get file attributes for FILE and put them in BUF. */
  172. extern int stat (__const char *__restrict __file,
  173. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  174. /* Get file attributes for the file, device, pipe, or socket
  175. that file descriptor FD is open on and put them in BUF. */
  176. extern int fstat (int __fd, struct stat *__buf) __THROW __nonnull ((2));
  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. #endif
  194. #ifdef __USE_ATFILE
  195. /* Similar to stat, get the attributes for FILE and put them in BUF.
  196. Relative path names are interpreted relative to FD unless FD is
  197. AT_FDCWD. */
  198. # ifndef __USE_FILE_OFFSET64
  199. extern int fstatat (int __fd, __const char *__restrict __file,
  200. struct stat *__restrict __buf, int __flag)
  201. __THROW __nonnull ((2, 3));
  202. # else
  203. # ifdef __REDIRECT_NTH
  204. extern int __REDIRECT_NTH (fstatat, (int __fd, __const char *__restrict __file,
  205. struct stat *__restrict __buf,
  206. int __flag),
  207. fstatat64) __nonnull ((2, 3));
  208. # else
  209. # define fstatat fstatat64
  210. # endif
  211. # endif
  212. # ifdef __USE_LARGEFILE64
  213. extern int fstatat64 (int __fd, __const char *__restrict __file,
  214. struct stat64 *__restrict __buf, int __flag)
  215. __THROW __nonnull ((2, 3));
  216. # endif
  217. #endif
  218. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
  219. # ifndef __USE_FILE_OFFSET64
  220. /* Get file attributes about FILE and put them in BUF.
  221. If FILE is a symbolic link, do not follow it. */
  222. extern int lstat (__const char *__restrict __file,
  223. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  224. # else
  225. # ifdef __REDIRECT_NTH
  226. extern int __REDIRECT_NTH (lstat,
  227. (__const char *__restrict __file,
  228. struct stat *__restrict __buf), lstat64)
  229. __nonnull ((1, 2));
  230. # else
  231. # define lstat lstat64
  232. # endif
  233. # endif
  234. # ifdef __USE_LARGEFILE64
  235. extern int lstat64 (__const char *__restrict __file,
  236. struct stat64 *__restrict __buf)
  237. __THROW __nonnull ((1, 2));
  238. # endif
  239. #endif
  240. /* Set file access permissions for FILE to MODE.
  241. If FILE is a symbolic link, this affects its target instead. */
  242. extern int chmod (__const char *__file, __mode_t __mode)
  243. __THROW __nonnull ((1));
  244. #ifdef __USE_BSD
  245. /* Set file access permissions for FILE to MODE.
  246. If FILE is a symbolic link, this affects the link itself
  247. rather than its target. */
  248. extern int lchmod (__const char *__file, __mode_t __mode)
  249. __THROW __nonnull ((1));
  250. #endif
  251. /* Set file access permissions of the file FD is open on to MODE. */
  252. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
  253. extern int fchmod (int __fd, __mode_t __mode) __THROW;
  254. #endif
  255. #ifdef __USE_ATFILE
  256. /* Set file access permissions of FILE relative to
  257. the directory FD is open on. */
  258. extern int fchmodat (int __fd, __const char *__file, __mode_t __mode,
  259. int __flag)
  260. __THROW __nonnull ((2)) __wur;
  261. #endif /* Use ATFILE. */
  262. /* Set the file creation mask of the current process to MASK,
  263. and return the old creation mask. */
  264. extern __mode_t umask (__mode_t __mask) __THROW;
  265. #ifdef __USE_GNU
  266. /* Get the current `umask' value without changing it.
  267. This function is only available under the GNU Hurd. */
  268. extern __mode_t getumask (void) __THROW;
  269. #endif
  270. /* Create a new directory named PATH, with permission bits MODE. */
  271. extern int mkdir (__const char *__path, __mode_t __mode)
  272. __THROW __nonnull ((1));
  273. #ifdef __USE_ATFILE
  274. /* Like mkdir, create a new directory with permission bits MODE. But
  275. interpret relative PATH names relative to the directory associated
  276. with FD. */
  277. extern int mkdirat (int __fd, __const char *__path, __mode_t __mode)
  278. __THROW __nonnull ((2));
  279. #endif
  280. /* Create a device file named PATH, with permission and special bits MODE
  281. and device number DEV (which can be constructed from major and minor
  282. device numbers with the `makedev' macro above). */
  283. #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  284. extern int mknod (__const char *__path, __mode_t __mode, __dev_t __dev)
  285. __THROW __nonnull ((1));
  286. # ifdef __USE_ATFILE
  287. /* Like mknod, create a new device file with permission bits MODE and
  288. device number DEV. But interpret relative PATH names relative to
  289. the directory associated with FD. */
  290. extern int mknodat (int __fd, __const char *__path, __mode_t __mode,
  291. __dev_t __dev) __THROW __nonnull ((2));
  292. # endif
  293. #endif
  294. /* Create a new FIFO named PATH, with permission bits MODE. */
  295. extern int mkfifo (__const char *__path, __mode_t __mode)
  296. __THROW __nonnull ((1));
  297. #ifdef __USE_ATFILE
  298. /* Like mkfifo, create a new FIFO with permission bits MODE. But
  299. interpret relative PATH names relative to the directory associated
  300. with FD. */
  301. extern int mkfifoat (int __fd, __const char *__path, __mode_t __mode)
  302. __THROW __nonnull ((2));
  303. #endif
  304. #ifdef __USE_ATFILE
  305. /* Set file access and modification times relative to directory file
  306. descriptor. */
  307. extern int utimensat (int __fd, __const char *__path,
  308. __const struct timespec __times[2],
  309. int __flags)
  310. __THROW __nonnull ((2));
  311. #endif
  312. #ifdef __USE_XOPEN2K8
  313. /* Set file access and modification times of the file associated with FD. */
  314. extern int futimens (int __fd, __const struct timespec __times[2]) __THROW;
  315. #endif
  316. /* To allow the `struct stat' structure and the file type `mode_t'
  317. bits to vary without changing shared library major version number,
  318. the `stat' family of functions and `mknod' are in fact inline
  319. wrappers around calls to `xstat', `fxstat', `lxstat', and `xmknod',
  320. which all take a leading version-number argument designating the
  321. data structure and bits used. <bits/stat.h> defines _STAT_VER with
  322. the version number corresponding to `struct stat' as defined in
  323. that file; and _MKNOD_VER with the version number corresponding to
  324. the S_IF* macros defined therein. It is arranged that when not
  325. inlined these function are always statically linked; that way a
  326. dynamically-linked executable always encodes the version number
  327. corresponding to the data structures it uses, so the `x' functions
  328. in the shared library can adapt without needing to recompile all
  329. callers. */
  330. #ifndef _STAT_VER
  331. # define _STAT_VER 0
  332. #endif
  333. #ifndef _MKNOD_VER
  334. # define _MKNOD_VER 0
  335. #endif
  336. /* Wrappers for stat and mknod system calls. */
  337. #ifndef __USE_FILE_OFFSET64
  338. extern int __fxstat (int __ver, int __fildes, struct stat *__stat_buf)
  339. __THROW __nonnull ((3));
  340. extern int __xstat (int __ver, __const char *__filename,
  341. struct stat *__stat_buf) __THROW __nonnull ((2, 3));
  342. extern int __lxstat (int __ver, __const char *__filename,
  343. struct stat *__stat_buf) __THROW __nonnull ((2, 3));
  344. extern int __fxstatat (int __ver, int __fildes, __const char *__filename,
  345. struct stat *__stat_buf, int __flag)
  346. __THROW __nonnull ((3, 4));
  347. #else
  348. # ifdef __REDIRECT_NTH
  349. extern int __REDIRECT_NTH (__fxstat, (int __ver, int __fildes,
  350. struct stat *__stat_buf), __fxstat64)
  351. __nonnull ((3));
  352. extern int __REDIRECT_NTH (__xstat, (int __ver, __const char *__filename,
  353. struct stat *__stat_buf), __xstat64)
  354. __nonnull ((2, 3));
  355. extern int __REDIRECT_NTH (__lxstat, (int __ver, __const char *__filename,
  356. struct stat *__stat_buf), __lxstat64)
  357. __nonnull ((2, 3));
  358. extern int __REDIRECT_NTH (__fxstatat, (int __ver, int __fildes,
  359. __const char *__filename,
  360. struct stat *__stat_buf, int __flag),
  361. __fxstatat64) __nonnull ((3, 4));
  362. # else
  363. # define __fxstat __fxstat64
  364. # define __xstat __xstat64
  365. # define __lxstat __lxstat64
  366. # endif
  367. #endif
  368. #ifdef __USE_LARGEFILE64
  369. extern int __fxstat64 (int __ver, int __fildes, struct stat64 *__stat_buf)
  370. __THROW __nonnull ((3));
  371. extern int __xstat64 (int __ver, __const char *__filename,
  372. struct stat64 *__stat_buf) __THROW __nonnull ((2, 3));
  373. extern int __lxstat64 (int __ver, __const char *__filename,
  374. struct stat64 *__stat_buf) __THROW __nonnull ((2, 3));
  375. extern int __fxstatat64 (int __ver, int __fildes, __const char *__filename,
  376. struct stat64 *__stat_buf, int __flag)
  377. __THROW __nonnull ((3, 4));
  378. #endif
  379. extern int __xmknod (int __ver, __const char *__path, __mode_t __mode,
  380. __dev_t *__dev) __THROW __nonnull ((2, 4));
  381. extern int __xmknodat (int __ver, int __fd, __const char *__path,
  382. __mode_t __mode, __dev_t *__dev)
  383. __THROW __nonnull ((3, 5));
  384. #if defined __GNUC__ && __GNUC__ >= 2 && defined __USE_EXTERN_INLINES
  385. /* Inlined versions of the real stat and mknod functions. */
  386. __extern_inline int
  387. __NTH (stat (__const char *__path, struct stat *__statbuf))
  388. {
  389. return __xstat (_STAT_VER, __path, __statbuf);
  390. }
  391. # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  392. __extern_inline int
  393. __NTH (lstat (__const char *__path, struct stat *__statbuf))
  394. {
  395. return __lxstat (_STAT_VER, __path, __statbuf);
  396. }
  397. # endif
  398. __extern_inline int
  399. __NTH (fstat (int __fd, struct stat *__statbuf))
  400. {
  401. return __fxstat (_STAT_VER, __fd, __statbuf);
  402. }
  403. # ifdef __USE_ATFILE
  404. __extern_inline int
  405. __NTH (fstatat (int __fd, __const char *__filename, struct stat *__statbuf,
  406. int __flag))
  407. {
  408. return __fxstatat (_STAT_VER, __fd, __filename, __statbuf, __flag);
  409. }
  410. # endif
  411. # if defined __USE_MISC || defined __USE_BSD
  412. __extern_inline int
  413. __NTH (mknod (__const char *__path, __mode_t __mode, __dev_t __dev))
  414. {
  415. return __xmknod (_MKNOD_VER, __path, __mode, &__dev);
  416. }
  417. # endif
  418. # ifdef __USE_ATFILE
  419. __extern_inline int
  420. __NTH (mknodat (int __fd, __const char *__path, __mode_t __mode,
  421. __dev_t __dev))
  422. {
  423. return __xmknodat (_MKNOD_VER, __fd, __path, __mode, &__dev);
  424. }
  425. # endif
  426. # if defined __USE_LARGEFILE64 \
  427. && (! defined __USE_FILE_OFFSET64 \
  428. || (defined __REDIRECT_NTH && defined __OPTIMIZE__))
  429. __extern_inline int
  430. __NTH (stat64 (__const char *__path, struct stat64 *__statbuf))
  431. {
  432. return __xstat64 (_STAT_VER, __path, __statbuf);
  433. }
  434. # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  435. __extern_inline int
  436. __NTH (lstat64 (__const char *__path, struct stat64 *__statbuf))
  437. {
  438. return __lxstat64 (_STAT_VER, __path, __statbuf);
  439. }
  440. # endif
  441. __extern_inline int
  442. __NTH (fstat64 (int __fd, struct stat64 *__statbuf))
  443. {
  444. return __fxstat64 (_STAT_VER, __fd, __statbuf);
  445. }
  446. # ifdef __USE_ATFILE
  447. __extern_inline int
  448. __NTH (fstatat64 (int __fd, __const char *__filename, struct stat64 *__statbuf,
  449. int __flag))
  450. {
  451. return __fxstatat64 (_STAT_VER, __fd, __filename, __statbuf, __flag);
  452. }
  453. # endif
  454. # endif
  455. #endif
  456. __END_DECLS
  457. #endif /* sys/stat.h */