stat.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /* Copyright (C) 1991, 92, 95, 96, 97, 98 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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  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. #ifdef __USE_XOPEN
  23. # define __need_time_t
  24. # include <time.h> /* For time_t. */
  25. /* The Single Unix specification says that some more types are
  26. available here. */
  27. # ifndef dev_t
  28. typedef __dev_t dev_t;
  29. # define dev_t dev_t
  30. # endif
  31. # ifndef gid_t
  32. typedef __gid_t gid_t;
  33. # define gid_t gid_t
  34. # endif
  35. # ifndef ino_t
  36. # ifndef __USE_FILE_OFFSET64
  37. typedef __ino_t ino_t;
  38. # else
  39. typedef __ino64_t ino_t;
  40. # endif
  41. # define ino_t ino_t
  42. # endif
  43. # ifndef mode_t
  44. typedef __mode_t mode_t;
  45. # define mode_t mode_t
  46. # endif
  47. # ifndef nlink_t
  48. typedef __nlink_t nlink_t;
  49. # define nlink_t nlink_t
  50. # endif
  51. # ifndef off_t
  52. # ifndef __USE_FILE_OFFSET64
  53. typedef __off_t off_t;
  54. # else
  55. typedef __off64_t off_t;
  56. # endif
  57. # define off_t off_t
  58. # endif
  59. # ifndef uid_t
  60. typedef __uid_t uid_t;
  61. # define uid_t uid_t
  62. # endif
  63. #endif /* X/Open */
  64. #ifdef __USE_UNIX98
  65. # ifndef pid_t
  66. typedef __pid_t pid_t;
  67. # define pid_t pid_t
  68. # endif
  69. #endif /* Unix98 */
  70. __BEGIN_DECLS
  71. #include <bits/stat.h>
  72. #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
  73. # define S_IFMT __S_IFMT
  74. # define S_IFDIR __S_IFDIR
  75. # define S_IFCHR __S_IFCHR
  76. # define S_IFBLK __S_IFBLK
  77. # define S_IFREG __S_IFREG
  78. # ifdef __S_IFIFO
  79. # define S_IFIFO __S_IFIFO
  80. # endif
  81. # if defined __USE_BSD || defined __USE_MISC
  82. # ifdef __S_IFLNK
  83. # define S_IFLNK __S_IFLNK
  84. # endif
  85. # ifdef __S_IFSOCK
  86. # define S_IFSOCK __S_IFSOCK
  87. # endif
  88. # endif
  89. #endif
  90. /* Test macros for file types. */
  91. #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
  92. #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
  93. #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR)
  94. #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK)
  95. #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
  96. #ifdef __S_IFIFO
  97. # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
  98. #endif
  99. #ifdef __USE_BSD
  100. # ifdef __S_IFLNK
  101. # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
  102. # else
  103. # define S_ISLNK(mode) 0
  104. # endif
  105. # ifdef __S_IFSOCK
  106. # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
  107. # endif
  108. #endif
  109. /* Protection bits. */
  110. #define S_ISUID __S_ISUID /* Set user ID on execution. */
  111. #define S_ISGID __S_ISGID /* Set group ID on execution. */
  112. #if defined __USE_BSD || defined __USE_MISC
  113. /* Save swapped text after use (sticky bit). This is pretty well obsolete. */
  114. # define S_ISVTX __S_ISVTX
  115. #endif
  116. #define S_IRUSR __S_IREAD /* Read by owner. */
  117. #define S_IWUSR __S_IWRITE /* Write by owner. */
  118. #define S_IXUSR __S_IEXEC /* Execute by owner. */
  119. /* Read, write, and execute by owner. */
  120. #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
  121. #if defined __USE_MISC && defined __USE_BSD
  122. # define S_IREAD S_IRUSR
  123. # define S_IWRITE S_IWUSR
  124. # define S_IEXEC S_IXUSR
  125. #endif
  126. #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
  127. #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
  128. #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
  129. /* Read, write, and execute by group. */
  130. #define S_IRWXG (S_IRWXU >> 3)
  131. #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
  132. #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
  133. #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
  134. /* Read, write, and execute by others. */
  135. #define S_IRWXO (S_IRWXG >> 3)
  136. #ifdef __USE_BSD
  137. /* Macros for common mode bit masks. */
  138. # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
  139. # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
  140. # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
  141. # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
  142. #endif
  143. #ifndef __USE_FILE_OFFSET64
  144. /* Get file attributes for FILE and put them in BUF. */
  145. extern int stat __P ((__const char *__file, struct stat *__buf));
  146. /* Get file attributes for the file, device, pipe, or socket
  147. that file descriptor FD is open on and put them in BUF. */
  148. extern int fstat __P ((int __fd, struct stat *__buf));
  149. #else
  150. # ifdef __REDIRECT
  151. extern int __REDIRECT (stat, __P ((__const char *__file, struct stat *__buf)),
  152. stat64);
  153. extern int __REDIRECT (fstat, __P ((int __fd, struct stat *__buf)), fstat64);
  154. # else
  155. # define stat stat64
  156. # define fstat fstat64
  157. # endif
  158. #endif
  159. #ifdef __USE_LARGEFILE64
  160. extern int stat64 __P ((__const char *__file, struct stat64 *__buf));
  161. extern int fstat64 __P ((int __fd, struct stat64 *__buf));
  162. #endif
  163. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  164. # ifndef __USE_FILE_OFFSET64
  165. /* Get file attributes about FILE and put them in BUF.
  166. If FILE is a symbolic link, do not follow it. */
  167. extern int lstat __P ((__const char *__file, struct stat *__buf));
  168. # else
  169. # ifdef __REDIRECT
  170. extern int __REDIRECT (lstat, __P ((__const char *__file, struct stat *__buf)),
  171. lstat64);
  172. # else
  173. # define lstat lstat64
  174. # endif
  175. # endif
  176. # ifdef __USE_LARGEFILE64
  177. extern int lstat64 __P ((__const char *__file, struct stat64 *__buf));
  178. # endif
  179. #endif
  180. /* Set file access permissions for FILE to MODE.
  181. This takes an `int' MODE argument because that
  182. is what `mode_t's get widened to. */
  183. extern int chmod __P ((__const char *__file, __mode_t __mode));
  184. /* Set file access permissions of the file FD is open on to MODE. */
  185. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  186. extern int fchmod __P ((int __fd, __mode_t __mode));
  187. #endif
  188. /* Set the file creation mask of the current process to MASK,
  189. and return the old creation mask. */
  190. extern __mode_t umask __P ((__mode_t __mask));
  191. #ifdef __USE_GNU
  192. /* Get the current `umask' value without changing it.
  193. This function is only available under the GNU Hurd. */
  194. extern __mode_t getumask __P ((void));
  195. #endif
  196. /* Create a new directory named PATH, with permission bits MODE. */
  197. extern int mkdir __P ((__const char *__path, __mode_t __mode));
  198. /* Create a device file named PATH, with permission and special bits MODE
  199. and device number DEV (which can be constructed from major and minor
  200. device numbers with the `makedev' macro above). */
  201. #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  202. extern int mknod __P ((__const char *__path,
  203. __mode_t __mode, __dev_t __dev));
  204. #endif
  205. /* Create a new FIFO named PATH, with permission bits MODE. */
  206. extern int mkfifo __P ((__const char *__path, __mode_t __mode));
  207. /* To allow the `struct stat' structure and the file type `mode_t'
  208. bits to vary without changing shared library major version number,
  209. the `stat' family of functions and `mknod' are in fact inline
  210. wrappers around calls to `xstat', `fxstat', `lxstat', and `xmknod',
  211. which all take a leading version-number argument designating the
  212. data structure and bits used. <bits/stat.h> defines _STAT_VER with
  213. the version number corresponding to `struct stat' as defined in
  214. that file; and _MKNOD_VER with the version number corresponding to
  215. the S_IF* macros defined therein. It is arranged that when not
  216. inlined these function are always statically linked; that way a
  217. dynamically-linked executable always encodes the version number
  218. corresponding to the data structures it uses, so the `x' functions
  219. in the shared library can adapt without needing to recompile all
  220. callers. */
  221. #ifndef _STAT_VER
  222. # define _STAT_VER 0
  223. #endif
  224. #ifndef _MKNOD_VER
  225. # define _MKNOD_VER 0
  226. #endif
  227. /* Wrappers for stat and mknod system calls. */
  228. #ifndef __USE_FILE_OFFSET64
  229. extern int _fxstat __P ((int __ver, int __fildes,
  230. struct stat *__stat_buf));
  231. extern int _xstat __P ((int __ver, __const char *__filename,
  232. struct stat *__stat_buf));
  233. extern int _lxstat __P ((int __ver, __const char *__filename,
  234. struct stat *__stat_buf));
  235. #else
  236. # ifdef __REDIRECT
  237. extern int __REDIRECT (_fxstat, __P ((int __ver, int __fildes,
  238. struct stat *__stat_buf)), _fxstat64);
  239. extern int __REDIRECT (_xstat, __P ((int __ver, __const char *__filename,
  240. struct stat *__stat_buf)), _xstat64);
  241. extern int __REDIRECT (_lxstat, __P ((int __ver, __const char *__filename,
  242. struct stat *__stat_buf)), _lxstat64);
  243. # else
  244. # define _fxstat _fxstat64
  245. # define _xstat _xstat64
  246. # define _lxstat _lxstat64
  247. # endif
  248. #endif
  249. #ifdef __USE_LARGEFILE64
  250. extern int _fxstat64 __P ((int __ver, int __fildes,
  251. struct stat64 *__stat_buf));
  252. extern int _xstat64 __P ((int __ver, __const char *__filename,
  253. struct stat64 *__stat_buf));
  254. extern int _lxstat64 __P ((int __ver, __const char *__filename,
  255. struct stat64 *__stat_buf));
  256. #endif
  257. extern int _xmknod __P ((int __ver, __const char *__path,
  258. __mode_t __mode, __dev_t *__dev));
  259. #if defined __GNUC__ && __GNUC__ >= 2
  260. /* Inlined versions of the real stat and mknod functions. */
  261. extern __inline__ int stat (__const char *__path,
  262. struct stat *__statbuf)
  263. {
  264. return _xstat (_STAT_VER, __path, __statbuf);
  265. }
  266. # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  267. extern __inline__ int lstat (__const char *__path,
  268. struct stat *__statbuf)
  269. {
  270. return _lxstat (_STAT_VER, __path, __statbuf);
  271. }
  272. # endif
  273. extern __inline__ int fstat (int __fd, struct stat *__statbuf)
  274. {
  275. return _fxstat (_STAT_VER, __fd, __statbuf);
  276. }
  277. # if defined __USE_MISC || defined __USE_BSD
  278. extern __inline__ int mknod (__const char *__path, __mode_t __mode,
  279. __dev_t __dev)
  280. {
  281. return _xmknod (_MKNOD_VER, __path, __mode, &__dev);
  282. }
  283. # endif
  284. # ifdef __USE_LARGEFILE64
  285. extern __inline__ int stat64 (__const char *__path,
  286. struct stat64 *__statbuf)
  287. {
  288. return _xstat64 (_STAT_VER, __path, __statbuf);
  289. }
  290. # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  291. extern __inline__ int lstat64 (__const char *__path,
  292. struct stat64 *__statbuf)
  293. {
  294. return _lxstat64 (_STAT_VER, __path, __statbuf);
  295. }
  296. # endif
  297. extern __inline__ int fstat64 (int __fd, struct stat64 *__statbuf)
  298. {
  299. return _fxstat64 (_STAT_VER, __fd, __statbuf);
  300. }
  301. # endif
  302. #endif
  303. __END_DECLS
  304. #endif /* sys/stat.h */