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