stat.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifndef _SYS_STAT_H
  2. #define _SYS_STAT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <_ansi.h>
  7. #include <time.h>
  8. #include <sys/cdefs.h>
  9. #include <sys/types.h>
  10. #include <sys/_timespec.h>
  11. /* dj's stat defines _STAT_H_ */
  12. #ifndef _STAT_H_
  13. /* It is intended that the layout of this structure not change when the
  14. sizes of any of the basic types change (short, int, long) [via a compile
  15. time option]. */
  16. #ifdef __CYGWIN__
  17. #include <cygwin/stat.h>
  18. #ifdef _COMPILING_NEWLIB
  19. #define stat64 stat
  20. #endif
  21. #else
  22. struct stat
  23. {
  24. dev_t st_dev;
  25. ino_t st_ino;
  26. mode_t st_mode;
  27. nlink_t st_nlink;
  28. uid_t st_uid;
  29. gid_t st_gid;
  30. dev_t st_rdev;
  31. off_t st_size;
  32. #if defined(__rtems__)
  33. struct timespec st_atim;
  34. struct timespec st_mtim;
  35. struct timespec st_ctim;
  36. blksize_t st_blksize;
  37. blkcnt_t st_blocks;
  38. #else
  39. /* SysV/sco doesn't have the rest... But Solaris, eabi does. */
  40. #if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
  41. time_t st_atime;
  42. time_t st_mtime;
  43. time_t st_ctime;
  44. #else
  45. time_t st_atime;
  46. long st_spare1;
  47. time_t st_mtime;
  48. long st_spare2;
  49. time_t st_ctime;
  50. long st_spare3;
  51. blksize_t st_blksize;
  52. blkcnt_t st_blocks;
  53. long st_spare4[2];
  54. #endif
  55. #endif
  56. };
  57. #if defined(__rtems__)
  58. #define st_atime st_atim.tv_sec
  59. #define st_ctime st_ctim.tv_sec
  60. #define st_mtime st_mtim.tv_sec
  61. #endif
  62. #endif
  63. #define _IFMT 0170000 /* type of file */
  64. #define _IFDIR 0040000 /* directory */
  65. #define _IFCHR 0020000 /* character special */
  66. #define _IFBLK 0060000 /* block special */
  67. #define _IFREG 0100000 /* regular */
  68. #define _IFLNK 0120000 /* symbolic link */
  69. #define _IFSOCK 0140000 /* socket */
  70. #define _IFIFO 0010000 /* fifo */
  71. #define S_BLKSIZE 1024 /* size of a block */
  72. #define S_ISUID 0004000 /* set user id on execution */
  73. #define S_ISGID 0002000 /* set group id on execution */
  74. #define S_ISVTX 0001000 /* save swapped text even after use */
  75. #if __BSD_VISIBLE
  76. #define S_IREAD 0000400 /* read permission, owner */
  77. #define S_IWRITE 0000200 /* write permission, owner */
  78. #define S_IEXEC 0000100 /* execute/search permission, owner */
  79. #define S_ENFMT 0002000 /* enforcement-mode locking */
  80. #endif /* !_BSD_VISIBLE */
  81. #define S_IFMT _IFMT
  82. #define S_IFDIR _IFDIR
  83. #define S_IFCHR _IFCHR
  84. #define S_IFBLK _IFBLK
  85. #define S_IFREG _IFREG
  86. #define S_IFLNK _IFLNK
  87. #define S_IFSOCK _IFSOCK
  88. #define S_IFIFO _IFIFO
  89. #ifdef _WIN32
  90. /* The Windows header files define _S_ forms of these, so we do too
  91. for easier portability. */
  92. #define _S_IFMT _IFMT
  93. #define _S_IFDIR _IFDIR
  94. #define _S_IFCHR _IFCHR
  95. #define _S_IFIFO _IFIFO
  96. #define _S_IFREG _IFREG
  97. #define _S_IREAD 0000400
  98. #define _S_IWRITE 0000200
  99. #define _S_IEXEC 0000100
  100. #endif
  101. #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
  102. #define S_IRUSR 0000400 /* read permission, owner */
  103. #define S_IWUSR 0000200 /* write permission, owner */
  104. #define S_IXUSR 0000100/* execute/search permission, owner */
  105. #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
  106. #define S_IRGRP 0000040 /* read permission, group */
  107. #define S_IWGRP 0000020 /* write permission, grougroup */
  108. #define S_IXGRP 0000010/* execute/search permission, group */
  109. #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
  110. #define S_IROTH 0000004 /* read permission, other */
  111. #define S_IWOTH 0000002 /* write permission, other */
  112. #define S_IXOTH 0000001/* execute/search permission, other */
  113. #if __BSD_VISIBLE
  114. #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
  115. #define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
  116. #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
  117. #endif
  118. #define S_ISBLK(m) (((m)&_IFMT) == _IFBLK)
  119. #define S_ISCHR(m) (((m)&_IFMT) == _IFCHR)
  120. #define S_ISDIR(m) (((m)&_IFMT) == _IFDIR)
  121. #define S_ISFIFO(m) (((m)&_IFMT) == _IFIFO)
  122. #define S_ISREG(m) (((m)&_IFMT) == _IFREG)
  123. #define S_ISLNK(m) (((m)&_IFMT) == _IFLNK)
  124. #define S_ISSOCK(m) (((m)&_IFMT) == _IFSOCK)
  125. #if defined(__CYGWIN__)
  126. /* Special tv_nsec values for futimens(2) and utimensat(2). */
  127. #define UTIME_NOW -2L
  128. #define UTIME_OMIT -1L
  129. #endif
  130. int chmod (const char *__path, mode_t __mode );
  131. int fchmod (int __fd, mode_t __mode);
  132. int fstat (int __fd, struct stat *__sbuf );
  133. int mkdir (const char *_path, mode_t __mode );
  134. int mkfifo (const char *__path, mode_t __mode );
  135. int stat (const char *__restrict __path, struct stat *__restrict __sbuf );
  136. mode_t umask (mode_t __mask );
  137. #if defined (__SPU__) || defined(__rtems__) || defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
  138. int lstat (const char *__restrict __path, struct stat *__restrict __buf );
  139. int mknod (const char *__path, mode_t __mode, dev_t __dev );
  140. #endif
  141. #if __ATFILE_VISIBLE && !defined(__INSIDE_CYGWIN__)
  142. int fchmodat (int, const char *, mode_t, int);
  143. int fstatat (int, const char *__restrict , struct stat *__restrict, int);
  144. int mkdirat (int, const char *, mode_t);
  145. int mkfifoat (int, const char *, mode_t);
  146. int mknodat (int, const char *, mode_t, dev_t);
  147. int utimensat (int, const char *, const struct timespec *, int);
  148. #endif
  149. #if __POSIX_VISIBLE >= 200809 && !defined(__INSIDE_CYGWIN__)
  150. int futimens (int, const struct timespec *);
  151. #endif
  152. /* Provide prototypes for most of the _<systemcall> names that are
  153. provided in newlib for some compilers. */
  154. #ifdef _COMPILING_NEWLIB
  155. int _fstat (int __fd, struct stat *__sbuf );
  156. int _stat (const char *__restrict __path, struct stat *__restrict __sbuf );
  157. int _mkdir (const char *_path, mode_t __mode );
  158. #ifdef __LARGE64_FILES
  159. struct stat64;
  160. int _stat64 (const char *__restrict __path, struct stat64 *__restrict __sbuf );
  161. int _fstat64 (int __fd, struct stat64 *__sbuf );
  162. #endif
  163. #endif
  164. #endif /* !_STAT_H_ */
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. #endif /* _SYS_STAT_H */