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