stat.h 7.5 KB

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