stat.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**
  2. * This file has no copyright assigned and is placed in the Public Domain.
  3. * This file is part of the w64 mingw-runtime package.
  4. * No warranty is given; refer to the file DISCLAIMER within this package.
  5. */
  6. #ifndef _INC_STAT
  7. #define _INC_STAT
  8. #ifndef _WIN32
  9. #error Only Win32 target is supported!
  10. #endif
  11. #include <_mingw.h>
  12. #include <io.h>
  13. #pragma pack(push,_CRT_PACKING)
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #ifndef _CRTIMP
  18. #define _CRTIMP __declspec(dllimport)
  19. #endif
  20. #include <sys/types.h>
  21. #ifndef __TINYC__ /* gr */
  22. #ifdef _USE_32BIT_TIME_T
  23. #ifdef _WIN64
  24. #undef _USE_32BIT_TIME_T
  25. #endif
  26. #else
  27. #if _INTEGRAL_MAX_BITS < 64
  28. #define _USE_32BIT_TIME_T
  29. #endif
  30. #endif
  31. #endif
  32. #ifndef _TIME32_T_DEFINED
  33. typedef long __time32_t;
  34. #define _TIME32_T_DEFINED
  35. #endif
  36. #ifndef _TIME64_T_DEFINED
  37. #if _INTEGRAL_MAX_BITS >= 64
  38. typedef __int64 __time64_t;
  39. #endif
  40. #define _TIME64_T_DEFINED
  41. #endif
  42. #ifndef _TIME_T_DEFINED
  43. #ifdef _USE_32BIT_TIME_T
  44. typedef __time32_t time_t;
  45. #else
  46. typedef __time64_t time_t;
  47. #endif
  48. #define _TIME_T_DEFINED
  49. #endif
  50. #ifndef _WCHAR_T_DEFINED
  51. typedef unsigned short wchar_t;
  52. #define _WCHAR_T_DEFINED
  53. #endif
  54. #ifndef _STAT_DEFINED
  55. #ifdef _USE_32BIT_TIME_T
  56. #ifndef _WIN64
  57. #define _fstat32 _fstat
  58. #define _stat32 _stat
  59. #define _wstat32 _wstat
  60. #else
  61. #define _fstat _fstat32
  62. #define _stat _stat32
  63. #define _wstat _wstat32
  64. #endif
  65. #define _fstati64 _fstat32i64
  66. #define _stati64 _stat32i64
  67. #define _wstati64 _wstat32i64
  68. #else
  69. #define _fstat _fstat64i32
  70. #define _fstati64 _fstat64
  71. #define _stat _stat64i32
  72. #define _stati64 _stat64
  73. #define _wstat _wstat64i32
  74. #define _wstati64 _wstat64
  75. #endif
  76. struct _stat32 {
  77. _dev_t st_dev;
  78. _ino_t st_ino;
  79. unsigned short st_mode;
  80. short st_nlink;
  81. short st_uid;
  82. short st_gid;
  83. _dev_t st_rdev;
  84. _off_t st_size;
  85. __time32_t st_atime;
  86. __time32_t st_mtime;
  87. __time32_t st_ctime;
  88. };
  89. #ifndef NO_OLDNAMES
  90. struct stat {
  91. _dev_t st_dev;
  92. _ino_t st_ino;
  93. unsigned short st_mode;
  94. short st_nlink;
  95. short st_uid;
  96. short st_gid;
  97. _dev_t st_rdev;
  98. _off_t st_size;
  99. time_t st_atime;
  100. time_t st_mtime;
  101. time_t st_ctime;
  102. };
  103. #endif
  104. #if _INTEGRAL_MAX_BITS >= 64
  105. struct _stat32i64 {
  106. _dev_t st_dev;
  107. _ino_t st_ino;
  108. unsigned short st_mode;
  109. short st_nlink;
  110. short st_uid;
  111. short st_gid;
  112. _dev_t st_rdev;
  113. __int64 st_size;
  114. __time32_t st_atime;
  115. __time32_t st_mtime;
  116. __time32_t st_ctime;
  117. };
  118. struct _stat64i32 {
  119. _dev_t st_dev;
  120. _ino_t st_ino;
  121. unsigned short st_mode;
  122. short st_nlink;
  123. short st_uid;
  124. short st_gid;
  125. _dev_t st_rdev;
  126. _off_t st_size;
  127. __time64_t st_atime;
  128. __time64_t st_mtime;
  129. __time64_t st_ctime;
  130. };
  131. struct _stat64 {
  132. _dev_t st_dev;
  133. _ino_t st_ino;
  134. unsigned short st_mode;
  135. short st_nlink;
  136. short st_uid;
  137. short st_gid;
  138. _dev_t st_rdev;
  139. __int64 st_size;
  140. __time64_t st_atime;
  141. __time64_t st_mtime;
  142. __time64_t st_ctime;
  143. };
  144. #endif
  145. #define __stat64 _stat64
  146. #define _STAT_DEFINED
  147. #endif
  148. #define _S_IFMT 0xF000
  149. #define _S_IFDIR 0x4000
  150. #define _S_IFCHR 0x2000
  151. #define _S_IFIFO 0x1000
  152. #define _S_IFREG 0x8000
  153. #define _S_IREAD 0x0100
  154. #define _S_IWRITE 0x0080
  155. #define _S_IEXEC 0x0040
  156. _CRTIMP int __cdecl _fstat32(int _FileDes,struct _stat32 *_Stat);
  157. _CRTIMP int __cdecl _stat32(const char *_Name,struct _stat32 *_Stat);
  158. #if _INTEGRAL_MAX_BITS >= 64
  159. _CRTIMP int __cdecl _fstat64(int _FileDes,struct _stat64 *_Stat);
  160. _CRTIMP int __cdecl _fstat32i64(int _FileDes,struct _stat32i64 *_Stat);
  161. int __cdecl _fstat64i32(int _FileDes,struct _stat64i32 *_Stat);
  162. __CRT_INLINE int __cdecl _fstat64i32(int _FileDes,struct _stat64i32 *_Stat)
  163. {
  164. struct _stat64 st;
  165. int ret=_fstat64(_FileDes,&st);
  166. _Stat->st_dev=st.st_dev;
  167. _Stat->st_ino=st.st_ino;
  168. _Stat->st_mode=st.st_mode;
  169. _Stat->st_nlink=st.st_nlink;
  170. _Stat->st_uid=st.st_uid;
  171. _Stat->st_gid=st.st_gid;
  172. _Stat->st_rdev=st.st_rdev;
  173. _Stat->st_size=(_off_t) st.st_size;
  174. _Stat->st_atime=st.st_atime;
  175. _Stat->st_mtime=st.st_mtime;
  176. _Stat->st_ctime=st.st_ctime;
  177. return ret;
  178. }
  179. _CRTIMP int __cdecl _stat64(const char *_Name,struct _stat64 *_Stat);
  180. _CRTIMP int __cdecl _stat32i64(const char *_Name,struct _stat32i64 *_Stat);
  181. int __cdecl _stat64i32(const char *_Name,struct _stat64i32 *_Stat);
  182. __CRT_INLINE int __cdecl _stat64i32(const char *_Name,struct _stat64i32 *_Stat)
  183. {
  184. struct _stat64 st;
  185. int ret=_stat64(_Name,&st);
  186. _Stat->st_dev=st.st_dev;
  187. _Stat->st_ino=st.st_ino;
  188. _Stat->st_mode=st.st_mode;
  189. _Stat->st_nlink=st.st_nlink;
  190. _Stat->st_uid=st.st_uid;
  191. _Stat->st_gid=st.st_gid;
  192. _Stat->st_rdev=st.st_rdev;
  193. _Stat->st_size=(_off_t) st.st_size;
  194. _Stat->st_atime=st.st_atime;
  195. _Stat->st_mtime=st.st_mtime;
  196. _Stat->st_ctime=st.st_ctime;
  197. return ret;
  198. }
  199. #endif
  200. #ifndef _WSTAT_DEFINED
  201. #define _WSTAT_DEFINED
  202. _CRTIMP int __cdecl _wstat32(const wchar_t *_Name,struct _stat32 *_Stat);
  203. #if _INTEGRAL_MAX_BITS >= 64
  204. _CRTIMP int __cdecl _wstat32i64(const wchar_t *_Name,struct _stat32i64 *_Stat);
  205. int __cdecl _wstat64i32(const wchar_t *_Name,struct _stat64i32 *_Stat);
  206. _CRTIMP int __cdecl _wstat64(const wchar_t *_Name,struct _stat64 *_Stat);
  207. #endif
  208. #endif
  209. #ifndef NO_OLDNAMES
  210. #define _S_IFBLK 0x3000 /* Block: Is this ever set under w32? */
  211. #define S_IFMT _S_IFMT
  212. #define S_IFDIR _S_IFDIR
  213. #define S_IFCHR _S_IFCHR
  214. #define S_IFREG _S_IFREG
  215. #define S_IREAD _S_IREAD
  216. #define S_IWRITE _S_IWRITE
  217. #define S_IEXEC _S_IEXEC
  218. #define S_IFIFO _S_IFIFO
  219. #define S_IFBLK _S_IFBLK
  220. #define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
  221. #define _S_IXUSR _S_IEXEC
  222. #define _S_IWUSR _S_IWRITE
  223. #define S_IRWXU _S_IRWXU
  224. #define S_IXUSR _S_IXUSR
  225. #define S_IWUSR _S_IWUSR
  226. #define S_IRUSR _S_IRUSR
  227. #define _S_IRUSR _S_IREAD
  228. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  229. #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  230. #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  231. #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  232. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  233. #endif
  234. #if !defined (RC_INVOKED) && !defined (NO_OLDNAMES)
  235. int __cdecl stat(const char *_Filename,struct stat *_Stat);
  236. int __cdecl fstat(int _Desc,struct stat *_Stat);
  237. int __cdecl wstat(const wchar_t *_Filename,struct stat *_Stat);
  238. #ifdef _USE_32BIT_TIME_T
  239. __CRT_INLINE int __cdecl fstat(int _Desc,struct stat *_Stat) {
  240. return _fstat32(_Desc,(struct _stat32 *)_Stat);
  241. }
  242. __CRT_INLINE int __cdecl stat(const char *_Filename,struct stat *_Stat) {
  243. return _stat32(_Filename,(struct _stat32 *)_Stat);
  244. }
  245. #else
  246. __CRT_INLINE int __cdecl fstat(int _Desc,struct stat *_Stat) {
  247. return _fstat64i32(_Desc,(struct _stat64i32 *)_Stat);
  248. }
  249. __CRT_INLINE int __cdecl stat(const char *_Filename,struct stat *_Stat) {
  250. return _stat64i32(_Filename,(struct _stat64i32 *)_Stat);
  251. }
  252. #endif
  253. #endif
  254. #ifdef __cplusplus
  255. }
  256. #endif
  257. #pragma pack(pop)
  258. #endif