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