stat.h 6.0 KB

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