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