1 /* 2 Copyright (c) 1982, 1986, 1993 3 The Regents of the University of California. All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions 7 are met: 8 1. Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 2. Redistributions in binary form must reproduce the above copyright 11 notice, this list of conditions and the following disclaimer in the 12 documentation and/or other materials provided with the distribution. 13 3. Neither the name of the University nor the names of its contributors 14 may be used to endorse or promote products derived from this software 15 without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 SUCH DAMAGE. 28 */ 29 #ifndef _SYS_STAT_H 30 #define _SYS_STAT_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #include <_ansi.h> 37 #include <time.h> 38 #include <sys/cdefs.h> 39 #include <sys/types.h> 40 #include <sys/_timespec.h> 41 42 /* dj's stat defines _STAT_H_ */ 43 #ifndef _STAT_H_ 44 45 /* It is intended that the layout of this structure not change when the 46 sizes of any of the basic types change (short, int, long) [via a compile 47 time option]. */ 48 49 #ifdef __CYGWIN__ 50 #include <cygwin/stat.h> 51 #ifdef _LIBC 52 #define stat64 stat 53 #endif 54 #else 55 struct stat 56 { 57 dev_t st_dev; 58 ino_t st_ino; 59 mode_t st_mode; 60 nlink_t st_nlink; 61 uid_t st_uid; 62 gid_t st_gid; 63 #if defined(__linux) && defined(__x86_64__) 64 int __pad0; 65 #endif 66 dev_t st_rdev; 67 #if defined(__linux) && !defined(__x86_64__) 68 unsigned short int __pad2; 69 #endif 70 off_t st_size; 71 #if defined(__linux) 72 blksize_t st_blksize; 73 blkcnt_t st_blocks; 74 struct timespec st_atim; 75 struct timespec st_mtim; 76 struct timespec st_ctim; 77 #define st_atime st_atim.tv_sec /* Backward compatibility */ 78 #define st_mtime st_mtim.tv_sec 79 #define st_ctime st_ctim.tv_sec 80 #if defined(__linux) && defined(__x86_64__) 81 __uint64_t __glibc_reserved[3]; 82 #endif 83 #else 84 #if defined(__rtems__) 85 struct timespec st_atim; 86 struct timespec st_mtim; 87 struct timespec st_ctim; 88 blksize_t st_blksize; 89 blkcnt_t st_blocks; 90 #else 91 /* SysV/sco doesn't have the rest... But Solaris, eabi does. */ 92 #if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__) 93 time_t st_atime; 94 time_t st_mtime; 95 time_t st_ctime; 96 #else 97 struct timespec st_atim; 98 struct timespec st_mtim; 99 struct timespec st_ctim; 100 blksize_t st_blksize; 101 blkcnt_t st_blocks; 102 #if !defined(__rtems__) 103 long st_spare4[2]; 104 #endif 105 #endif 106 #endif 107 #endif 108 }; 109 110 #if !(defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)) 111 #define st_atime st_atim.tv_sec 112 #define st_ctime st_ctim.tv_sec 113 #define st_mtime st_mtim.tv_sec 114 #endif 115 116 #endif 117 118 #define _IFMT 0170000 /* type of file */ 119 #define _IFDIR 0040000 /* directory */ 120 #define _IFCHR 0020000 /* character special */ 121 #define _IFBLK 0060000 /* block special */ 122 #define _IFREG 0100000 /* regular */ 123 #define _IFLNK 0120000 /* symbolic link */ 124 #define _IFSOCK 0140000 /* socket */ 125 #define _IFIFO 0010000 /* fifo */ 126 127 #define S_BLKSIZE 1024 /* size of a block */ 128 129 #define S_ISUID 0004000 /* set user id on execution */ 130 #define S_ISGID 0002000 /* set group id on execution */ 131 #define S_ISVTX 0001000 /* save swapped text even after use */ 132 #if __BSD_VISIBLE 133 #define S_IREAD 0000400 /* read permission, owner */ 134 #define S_IWRITE 0000200 /* write permission, owner */ 135 #define S_IEXEC 0000100 /* execute/search permission, owner */ 136 #define S_ENFMT 0002000 /* enforcement-mode locking */ 137 #endif /* !_BSD_VISIBLE */ 138 139 #define S_IFMT _IFMT 140 #define S_IFDIR _IFDIR 141 #define S_IFCHR _IFCHR 142 #define S_IFBLK _IFBLK 143 #define S_IFREG _IFREG 144 #define S_IFLNK _IFLNK 145 #define S_IFSOCK _IFSOCK 146 #define S_IFIFO _IFIFO 147 148 #ifdef _WIN32 149 /* The Windows header files define _S_ forms of these, so we do too 150 for easier portability. */ 151 #define _S_IFMT _IFMT 152 #define _S_IFDIR _IFDIR 153 #define _S_IFCHR _IFCHR 154 #define _S_IFIFO _IFIFO 155 #define _S_IFREG _IFREG 156 #define _S_IREAD 0000400 157 #define _S_IWRITE 0000200 158 #define _S_IEXEC 0000100 159 #endif 160 161 #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) 162 #define S_IRUSR 0000400 /* read permission, owner */ 163 #define S_IWUSR 0000200 /* write permission, owner */ 164 #define S_IXUSR 0000100/* execute/search permission, owner */ 165 #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) 166 #define S_IRGRP 0000040 /* read permission, group */ 167 #define S_IWGRP 0000020 /* write permission, grougroup */ 168 #define S_IXGRP 0000010/* execute/search permission, group */ 169 #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) 170 #define S_IROTH 0000004 /* read permission, other */ 171 #define S_IWOTH 0000002 /* write permission, other */ 172 #define S_IXOTH 0000001/* execute/search permission, other */ 173 174 #if __BSD_VISIBLE 175 #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */ 176 #define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */ 177 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */ 178 #endif 179 180 #define S_ISBLK(m) (((m)&_IFMT) == _IFBLK) 181 #define S_ISCHR(m) (((m)&_IFMT) == _IFCHR) 182 #define S_ISDIR(m) (((m)&_IFMT) == _IFDIR) 183 #define S_ISFIFO(m) (((m)&_IFMT) == _IFIFO) 184 #define S_ISREG(m) (((m)&_IFMT) == _IFREG) 185 #define S_ISLNK(m) (((m)&_IFMT) == _IFLNK) 186 #define S_ISSOCK(m) (((m)&_IFMT) == _IFSOCK) 187 188 #if defined(__CYGWIN__) || defined(__rtems__) 189 /* Special tv_nsec values for futimens(2) and utimensat(2). */ 190 #define UTIME_NOW -2L 191 #define UTIME_OMIT -1L 192 #endif 193 194 int chmod (const char *__path, mode_t __mode ); 195 int fchmod (int __fd, mode_t __mode); 196 int fstat (int __fd, struct stat *__sbuf ); 197 int mkdir (const char *_path, mode_t __mode ); 198 int mkfifo (const char *__path, mode_t __mode ); 199 int stat (const char *__restrict __path, struct stat *__restrict __sbuf ); 200 mode_t umask (mode_t __mask ); 201 202 #if defined (__SPU__) || defined(__rtems__) || defined(__CYGWIN__) 203 int lstat (const char *__restrict __path, struct stat *__restrict __buf ); 204 int mknod (const char *__path, mode_t __mode, dev_t __dev ); 205 #endif 206 207 #if __ATFILE_VISIBLE && !defined(__INSIDE_CYGWIN__) 208 int fchmodat (int, const char *, mode_t, int); 209 int fstatat (int, const char *__restrict , struct stat *__restrict, int); 210 int mkdirat (int, const char *, mode_t); 211 int mkfifoat (int, const char *, mode_t); 212 int mknodat (int, const char *, mode_t, dev_t); 213 int utimensat (int, const char *, const struct timespec [2], int); 214 #endif 215 #if __POSIX_VISIBLE >= 200809 && !defined(__INSIDE_CYGWIN__) 216 int futimens (int, const struct timespec [2]); 217 #endif 218 219 /* Provide prototypes for most of the _<systemcall> names that are 220 provided in newlib for some compilers. */ 221 #ifdef _LIBC 222 int _fstat (int __fd, struct stat *__sbuf ); 223 int _stat (const char *__restrict __path, struct stat *__restrict __sbuf ); 224 int _mkdir (const char *_path, mode_t __mode ); 225 #ifdef __LARGE64_FILES 226 struct stat64; 227 int _stat64 (const char *__restrict __path, struct stat64 *__restrict __sbuf ); 228 int _fstat64 (int __fd, struct stat64 *__sbuf ); 229 #endif 230 #endif 231 232 #endif /* !_STAT_H_ */ 233 #ifdef __cplusplus 234 } 235 #endif 236 #endif /* _SYS_STAT_H */ 237