stat.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Copyright (C) 1991-2026 Free Software Foundation, Inc.
  17. This file is part of the GNU C Library.
  18. The GNU C Library is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU Lesser General Public
  20. License as published by the Free Software Foundation; either
  21. version 2.1 of the License, or (at your option) any later version.
  22. The GNU C Library is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. Lesser General Public License for more details.
  26. You should have received a copy of the GNU Lesser General Public
  27. License along with the GNU C Library; if not, see
  28. <https://www.gnu.org/licenses/>. */
  29. /*
  30. * POSIX Standard: 5.6 File Characteristics <sys/stat.h>
  31. */
  32. #ifndef _SYS_STAT_H
  33. #define _SYS_STAT_H 1
  34. #include <features.h>
  35. #include <bits/types.h> /* For __mode_t and __dev_t. */
  36. #if defined(__USE_ATFILE) || defined(__USE_XOPEN2K8)
  37. # include <bits/types/struct_timespec.h>
  38. #endif
  39. #if defined __USE_XOPEN || defined __USE_XOPEN2K
  40. /* The Single Unix specification says that some more types are
  41. available here. */
  42. # include <bits/types/time_t.h>
  43. # ifndef __dev_t_defined
  44. typedef __dev_t dev_t;
  45. # define __dev_t_defined
  46. # endif
  47. # ifndef __gid_t_defined
  48. typedef __gid_t gid_t;
  49. # define __gid_t_defined
  50. # endif
  51. # ifndef __ino_t_defined
  52. # ifndef __USE_FILE_OFFSET64
  53. typedef __ino_t ino_t;
  54. # else
  55. typedef __ino64_t ino_t;
  56. # endif
  57. # define __ino_t_defined
  58. # endif
  59. # ifndef __mode_t_defined
  60. typedef __mode_t mode_t;
  61. # define __mode_t_defined
  62. # endif
  63. # ifndef __nlink_t_defined
  64. typedef __nlink_t nlink_t;
  65. # define __nlink_t_defined
  66. # endif
  67. # ifndef __off_t_defined
  68. # ifndef __USE_FILE_OFFSET64
  69. typedef __off_t off_t;
  70. # else
  71. typedef __off64_t off_t;
  72. # endif
  73. # define __off_t_defined
  74. # endif
  75. # ifndef __uid_t_defined
  76. typedef __uid_t uid_t;
  77. # define __uid_t_defined
  78. # endif
  79. #endif /* X/Open */
  80. #ifdef __USE_UNIX98
  81. # ifndef __blkcnt_t_defined
  82. # ifndef __USE_FILE_OFFSET64
  83. typedef __blkcnt_t blkcnt_t;
  84. # else
  85. typedef __blkcnt64_t blkcnt_t;
  86. # endif
  87. # define __blkcnt_t_defined
  88. # endif
  89. # ifndef __blksize_t_defined
  90. typedef __blksize_t blksize_t;
  91. # define __blksize_t_defined
  92. # endif
  93. #endif /* Unix98 */
  94. __BEGIN_DECLS
  95. #include <bits/stat.h>
  96. #if defined __USE_MISC || defined __USE_XOPEN
  97. # define S_IFMT __S_IFMT
  98. # define S_IFDIR __S_IFDIR
  99. # define S_IFCHR __S_IFCHR
  100. # define S_IFBLK __S_IFBLK
  101. # define S_IFREG __S_IFREG
  102. # ifdef __S_IFIFO
  103. # define S_IFIFO __S_IFIFO
  104. # endif
  105. # ifdef __S_IFLNK
  106. # define S_IFLNK __S_IFLNK
  107. # endif
  108. # if (defined __USE_MISC || defined __USE_XOPEN_EXTENDED) \
  109. && defined __S_IFSOCK
  110. # define S_IFSOCK __S_IFSOCK
  111. # endif
  112. #endif
  113. /* Test macros for file types. */
  114. #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
  115. #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
  116. #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR)
  117. #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK)
  118. #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
  119. #ifdef __S_IFIFO
  120. # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
  121. #endif
  122. #ifdef __S_IFLNK
  123. # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
  124. #endif
  125. #if defined __USE_MISC && !defined __S_IFLNK
  126. # define S_ISLNK(mode) 0
  127. #endif
  128. #if (defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K) \
  129. && defined __S_IFSOCK
  130. # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
  131. #elif defined __USE_XOPEN2K
  132. # define S_ISSOCK(mode) 0
  133. #endif
  134. /* These are from POSIX.1b. If the objects are not implemented using separate
  135. distinct file types, the macros always will evaluate to zero. Unlike the
  136. other S_* macros the following three take a pointer to a `struct stat'
  137. object as the argument. */
  138. #ifdef __USE_POSIX199309
  139. # define S_TYPEISMQ(buf) __S_TYPEISMQ(buf)
  140. # define S_TYPEISSEM(buf) __S_TYPEISSEM(buf)
  141. # define S_TYPEISSHM(buf) __S_TYPEISSHM(buf)
  142. #endif
  143. /* Protection bits. */
  144. #define S_ISUID __S_ISUID /* Set user ID on execution. */
  145. #define S_ISGID __S_ISGID /* Set group ID on execution. */
  146. #if defined __USE_MISC || defined __USE_XOPEN
  147. /* Save swapped text after use (sticky bit). This is pretty well obsolete. */
  148. # define S_ISVTX __S_ISVTX
  149. #endif
  150. #define S_IRUSR __S_IREAD /* Read by owner. */
  151. #define S_IWUSR __S_IWRITE /* Write by owner. */
  152. #define S_IXUSR __S_IEXEC /* Execute by owner. */
  153. /* Read, write, and execute by owner. */
  154. #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
  155. #ifdef __USE_MISC
  156. # define S_IREAD S_IRUSR
  157. # define S_IWRITE S_IWUSR
  158. # define S_IEXEC S_IXUSR
  159. #endif
  160. #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
  161. #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
  162. #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
  163. /* Read, write, and execute by group. */
  164. #define S_IRWXG (S_IRWXU >> 3)
  165. #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
  166. #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
  167. #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
  168. /* Read, write, and execute by others. */
  169. #define S_IRWXO (S_IRWXG >> 3)
  170. #ifdef __USE_MISC
  171. /* Macros for common mode bit masks. */
  172. # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
  173. # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
  174. # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
  175. # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
  176. #endif
  177. #ifndef __USE_FILE_OFFSET64
  178. /* Get file attributes for FILE and put them in BUF. */
  179. extern int stat (const char *__restrict __file,
  180. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  181. /* Get file attributes for the file, device, pipe, or socket
  182. that file descriptor FD is open on and put them in BUF. */
  183. extern int fstat (int __fd, struct stat *__buf) __THROW __nonnull ((2));
  184. #else
  185. # ifdef __USE_TIME64_REDIRECTS
  186. # ifdef __REDIRECT_NTH
  187. extern int __REDIRECT_NTH (stat, (const char *__restrict __file,
  188. struct stat *__restrict __buf),
  189. __stat64_time64)
  190. __nonnull ((1, 2));
  191. extern int __REDIRECT_NTH (fstat, (int __fd, struct stat *__buf),
  192. __fstat64_time64)
  193. __nonnull ((2));
  194. # else
  195. # define stat __stat64_time64
  196. # define fstat __fstat64_time64
  197. # endif
  198. # else
  199. # ifdef __REDIRECT_NTH
  200. extern int __REDIRECT_NTH (stat, (const char *__restrict __file,
  201. struct stat *__restrict __buf), stat64)
  202. __nonnull ((1, 2));
  203. extern int __REDIRECT_NTH (fstat, (int __fd, struct stat *__buf), fstat64)
  204. __nonnull ((2));
  205. # else
  206. # define stat stat64
  207. # define fstat fstat64
  208. # endif
  209. # endif
  210. #endif
  211. #ifdef __USE_LARGEFILE64
  212. # ifndef __USE_TIME64_REDIRECTS
  213. extern int stat64 (const char *__restrict __file,
  214. struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2));
  215. extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
  216. # else
  217. # ifdef __REDIRECT_NTH
  218. extern int __REDIRECT_NTH (stat64, (const char *__restrict __file,
  219. struct stat64 *__restrict __buf),
  220. __stat64_time64)
  221. __nonnull ((1, 2));
  222. extern int __REDIRECT_NTH (fstat64, (int __fd, struct stat64 *__buf),
  223. __fstat64_time64)
  224. __nonnull ((2));
  225. # else
  226. # define stat64 __stat64_time64
  227. # define fstat64 __fstat64_time64
  228. # endif
  229. # endif
  230. #endif
  231. #ifdef __USE_ATFILE
  232. /* Similar to stat, get the attributes for FILE and put them in BUF.
  233. Relative path names are interpreted relative to FD unless FD is
  234. AT_FDCWD. */
  235. # ifndef __USE_FILE_OFFSET64
  236. extern int fstatat (int __fd, const char *__restrict __file,
  237. struct stat *__restrict __buf, int __flag)
  238. __THROW __nonnull ((3));
  239. # else
  240. # ifdef __USE_TIME64_REDIRECTS
  241. # ifdef __REDIRECT_NTH
  242. extern int __REDIRECT_NTH (fstatat, (int __fd, const char *__restrict __file,
  243. struct stat *__restrict __buf,
  244. int __flag),
  245. __fstatat64_time64) __nonnull ((3));
  246. # else
  247. # define fstatat __fstatat64_time64
  248. # endif
  249. # else
  250. # ifdef __REDIRECT_NTH
  251. extern int __REDIRECT_NTH (fstatat, (int __fd, const char *__restrict __file,
  252. struct stat *__restrict __buf,
  253. int __flag),
  254. fstatat64) __nonnull ((3));
  255. # else
  256. # define fstatat fstatat64
  257. # endif
  258. # endif
  259. # endif
  260. # ifdef __USE_LARGEFILE64
  261. # ifndef __USE_TIME64_REDIRECTS
  262. extern int fstatat64 (int __fd, const char *__restrict __file,
  263. struct stat64 *__restrict __buf, int __flag)
  264. __THROW __nonnull ((3));
  265. # else
  266. # ifdef __REDIRECT_NTH
  267. extern int __REDIRECT_NTH (fstatat64, (int __fd,
  268. const char *__restrict __file,
  269. struct stat64 *__restrict __buf,
  270. int __flag),
  271. __fstatat64_time64)
  272. __nonnull ((3));
  273. # else
  274. # define fstatat64 __fstatat64_time64
  275. # endif
  276. # endif
  277. # endif
  278. #endif
  279. #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
  280. # ifndef __USE_FILE_OFFSET64
  281. /* Get file attributes about FILE and put them in BUF.
  282. If FILE is a symbolic link, do not follow it. */
  283. extern int lstat (const char *__restrict __file,
  284. struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
  285. # else
  286. # ifdef __USE_TIME64_REDIRECTS
  287. # ifdef __REDIRECT_NTH
  288. extern int __REDIRECT_NTH (lstat,
  289. (const char *__restrict __file,
  290. struct stat *__restrict __buf), __lstat64_time64)
  291. __nonnull ((1, 2));
  292. # else
  293. # define lstat __lstat64_time64
  294. # endif
  295. # else
  296. # ifdef __REDIRECT_NTH
  297. extern int __REDIRECT_NTH (lstat,
  298. (const char *__restrict __file,
  299. struct stat *__restrict __buf), lstat64)
  300. __nonnull ((1, 2));
  301. # else
  302. # define lstat lstat64
  303. # endif
  304. # endif
  305. # endif
  306. # ifdef __USE_LARGEFILE64
  307. # ifndef __USE_TIME64_REDIRECTS
  308. extern int lstat64 (const char *__restrict __file,
  309. struct stat64 *__restrict __buf)
  310. __THROW __nonnull ((1, 2));
  311. # else
  312. extern int __REDIRECT_NTH (lstat64, (const char *__restrict __file,
  313. struct stat64 *__restrict __buf),
  314. __lstat64_time64)
  315. __nonnull ((1, 2));
  316. # endif
  317. # endif
  318. #endif
  319. /* Set file access permissions for FILE to MODE.
  320. If FILE is a symbolic link, this affects its target instead. */
  321. extern int chmod (const char *__file, __mode_t __mode)
  322. __THROW __nonnull ((1));
  323. #ifdef __USE_MISC
  324. /* Set file access permissions for FILE to MODE.
  325. If FILE is a symbolic link, this affects the link itself
  326. rather than its target. */
  327. extern int lchmod (const char *__file, __mode_t __mode)
  328. __THROW __nonnull ((1));
  329. #endif
  330. /* Set file access permissions of the file FD is open on to MODE. */
  331. #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
  332. extern int fchmod (int __fd, __mode_t __mode) __THROW;
  333. #endif
  334. #ifdef __USE_ATFILE
  335. /* Set file access permissions of FILE relative to
  336. the directory FD is open on. */
  337. extern int fchmodat (int __fd, const char *__file, __mode_t __mode,
  338. int __flag)
  339. __THROW __nonnull ((2)) __wur;
  340. #endif /* Use ATFILE. */
  341. /* Set the file creation mask of the current process to MASK,
  342. and return the old creation mask. */
  343. extern __mode_t umask (__mode_t __mask) __THROW;
  344. #ifdef __USE_GNU
  345. /* Get the current `umask' value without changing it.
  346. This function is only available under the GNU Hurd. */
  347. extern __mode_t getumask (void) __THROW;
  348. #endif
  349. /* Create a new directory named PATH, with permission bits MODE. */
  350. extern int mkdir (const char *__path, __mode_t __mode)
  351. __THROW __nonnull ((1));
  352. #ifdef __USE_ATFILE
  353. /* Like mkdir, create a new directory with permission bits MODE. But
  354. interpret relative PATH names relative to the directory associated
  355. with FD. */
  356. extern int mkdirat (int __fd, const char *__path, __mode_t __mode)
  357. __THROW __nonnull ((2));
  358. #endif
  359. /* Create a device file named PATH, with permission and special bits MODE
  360. and device number DEV (which can be constructed from major and minor
  361. device numbers with the `makedev' macro above). */
  362. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  363. extern int mknod (const char *__path, __mode_t __mode, __dev_t __dev)
  364. __THROW __nonnull ((1));
  365. # ifdef __USE_ATFILE
  366. /* Like mknod, create a new device file with permission bits MODE and
  367. device number DEV. But interpret relative PATH names relative to
  368. the directory associated with FD. */
  369. extern int mknodat (int __fd, const char *__path, __mode_t __mode,
  370. __dev_t __dev) __THROW __nonnull ((2));
  371. # endif
  372. #endif
  373. /* Create a new FIFO named PATH, with permission bits MODE. */
  374. extern int mkfifo (const char *__path, __mode_t __mode)
  375. __THROW __nonnull ((1));
  376. #ifdef __USE_ATFILE
  377. /* Like mkfifo, create a new FIFO with permission bits MODE. But
  378. interpret relative PATH names relative to the directory associated
  379. with FD. */
  380. extern int mkfifoat (int __fd, const char *__path, __mode_t __mode)
  381. __THROW __nonnull ((2));
  382. #endif
  383. #ifdef __USE_ATFILE
  384. # ifndef __USE_TIME64_REDIRECTS
  385. /* Set file access and modification times relative to directory file
  386. descriptor. */
  387. extern int utimensat (int __fd, const char *__path,
  388. const struct timespec __times[2],
  389. int __flags)
  390. __THROW;
  391. # else
  392. # ifdef __REDIRECT_NTH
  393. extern int __REDIRECT_NTH (utimensat, (int fd, const char *__path,
  394. const struct timespec __times[2],
  395. int flags),
  396. __utimensat64);
  397. # else
  398. # define utimensat __utimensat64
  399. # endif
  400. # endif
  401. #endif
  402. #ifdef __USE_XOPEN2K8
  403. # ifndef __USE_TIME64_REDIRECTS
  404. /* Set file access and modification times of the file associated with FD. */
  405. extern int futimens (int __fd, const struct timespec __times[2]) __THROW;
  406. # else
  407. # ifdef __REDIRECT_NTH
  408. extern int __REDIRECT_NTH (futimens, (int fd, const struct timespec __times[2]),
  409. __futimens64);
  410. # else
  411. # define futimens __futimens64
  412. # endif
  413. # endif
  414. #endif
  415. #ifdef __USE_GNU
  416. # include <bits/statx.h>
  417. #endif
  418. __END_DECLS
  419. #endif /* sys/stat.h */