xref: /reactos/sdk/include/crt/sys/stat.h (revision 50cf16b3)
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 <crtdefs.h>
14 
15 #pragma pack(push,_CRT_PACKING)
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include <sys/types.h>
22 
23 #ifndef _STAT_DEFINED
24 #define _STAT_DEFINED
25 
26   struct _stat32 {
27     _dev_t st_dev;
28     _ino_t st_ino;
29     unsigned short st_mode;
30     short st_nlink;
31     short st_uid;
32     short st_gid;
33     _dev_t st_rdev;
34     _off_t st_size;
35     __time32_t st_atime;
36     __time32_t st_mtime;
37     __time32_t st_ctime;
38   };
39 
40   struct _stat {
41     _dev_t st_dev;
42     _ino_t st_ino;
43     unsigned short st_mode;
44     short st_nlink;
45     short st_uid;
46     short st_gid;
47     _dev_t st_rdev;
48     _off_t st_size;
49     time_t st_atime;
50     time_t st_mtime;
51     time_t st_ctime;
52   };
53 
54 #ifndef	NO_OLDNAMES
55   struct stat {
56     _dev_t st_dev;
57     _ino_t st_ino;
58     unsigned short st_mode;
59     short st_nlink;
60     short st_uid;
61     short st_gid;
62     _dev_t st_rdev;
63     _off_t st_size;
64     time_t st_atime;
65     time_t st_mtime;
66     time_t st_ctime;
67   };
68 #endif
69 
70 #if _INTEGRAL_MAX_BITS >= 64
71   struct _stat32i64 {
72     _dev_t st_dev;
73     _ino_t st_ino;
74     unsigned short st_mode;
75     short st_nlink;
76     short st_uid;
77     short st_gid;
78     _dev_t st_rdev;
79     __int64 st_size;
80     __time32_t st_atime;
81     __time32_t st_mtime;
82     __time32_t st_ctime;
83   };
84 
85   struct _stat64i32 {
86     _dev_t st_dev;
87     _ino_t st_ino;
88     unsigned short st_mode;
89     short st_nlink;
90     short st_uid;
91     short st_gid;
92     _dev_t st_rdev;
93     _off_t st_size;
94     __time64_t st_atime;
95     __time64_t st_mtime;
96     __time64_t st_ctime;
97   };
98 
99   struct _stat64 {
100     _dev_t st_dev;
101     _ino_t st_ino;
102     unsigned short st_mode;
103     short st_nlink;
104     short st_uid;
105     short st_gid;
106     _dev_t st_rdev;
107     __int64 st_size;
108     __time64_t st_atime;
109     __time64_t st_mtime;
110     __time64_t st_ctime;
111   };
112 
113   struct _stati64 {
114     _dev_t st_dev;
115     _ino_t st_ino;
116     unsigned short st_mode;
117     short st_nlink;
118     short st_uid;
119     short st_gid;
120     _dev_t st_rdev;
121     __int64 st_size;
122     time_t st_atime;
123     time_t st_mtime;
124     time_t st_ctime;
125   };
126 
127 #endif /* _INTEGRAL_MAX_BITS >= 64 */
128 
129 #define __stat64 _stat64
130 
131 #endif /* !_STAT_DEFINED */
132 
133 #define _S_IFMT 0xF000
134 #define _S_IFDIR 0x4000
135 #define _S_IFCHR 0x2000
136 #define _S_IFIFO 0x1000
137 #define _S_IFREG 0x8000
138 #define _S_IREAD 0x0100
139 #define _S_IWRITE 0x0080
140 #define _S_IEXEC 0x0040
141 
142   _CRTIMP
143   int
144   __cdecl
145   _fstat(
146     _In_ int _FileDes,
147     _Out_ struct _stat *_Stat);
148 
149   _CRTIMP
150   int
151   __cdecl
152   _fstat32(
153     _In_ int _FileDes,
154     _Out_ struct _stat32 *_Stat);
155 
156   _CRTIMP
157   int
158   __cdecl
159   _stat(
160     _In_z_ const char *_Name,
161     _Out_ struct _stat *_Stat);
162 
163   _CRTIMP
164   int
165   __cdecl
166   _stat32(
167     _In_z_ const char *_Name,
168     _Out_ struct _stat32 *_Stat);
169 
170 #if _INTEGRAL_MAX_BITS >= 64
171 
172   _CRTIMP
173   int
174   __cdecl
175   _fstat64(
176     _In_ int _FileDes,
177     _Out_ struct _stat64 *_Stat);
178 
179   _CRTIMP
180   int
181   __cdecl
182   _fstat32i64(
183     _In_ int _FileDes,
184     _Out_ struct _stat32i64 *_Stat);
185 
186   _CRTIMP
187   int
188   __cdecl
189   _fstat64i32(
190     _In_ int _FileDes,
191     _Out_ struct _stat64i32 *_Stat);
192 
193   _CRTIMP
194   int
195   __cdecl
196   _stat64(
197     _In_z_ const char *_Name,
198     _Out_ struct _stat64 *_Stat);
199 
200   _CRTIMP
201   int
202   __cdecl
203   _stat32i64(
204     _In_z_ const char *_Name,
205     _Out_ struct _stat32i64 *_Stat);
206 
207   _CRTIMP
208   int
209   __cdecl
210   _stat64i32(
211     _In_z_ const char *_Name,
212     _Out_ struct _stat64i32 *_Stat);
213 
214 #endif /* _INTEGRAL_MAX_BITS >= 64 */
215 
216 #ifndef _WSTAT_DEFINED
217 #define _WSTAT_DEFINED
218 
219   _CRTIMP
220   int
221   __cdecl
222   _wstat(
223     _In_z_ const wchar_t *_Name,
224     _Out_ struct _stat *_Stat);
225 
226   _CRTIMP
227   int
228   __cdecl
229   _wstat32(
230     _In_z_ const wchar_t *_Name,
231     _Out_ struct _stat32 *_Stat);
232 
233 #if _INTEGRAL_MAX_BITS >= 64
234   _CRTIMP
235   int
236   __cdecl
237   _wstat32i64(
238     _In_z_ const wchar_t *_Name,
239     _Out_ struct _stat32i64 *_Stat);
240 
241   _CRTIMP
242   int
243   __cdecl
244   _wstat64i32(
245     _In_z_ const wchar_t *_Name,
246     _Out_ struct _stat64i32 *_Stat);
247 
248   _CRTIMP
249   int
250   __cdecl
251   _wstat64(
252     _In_z_ const wchar_t *_Name,
253     _Out_ struct _stat64 *_Stat);
254 
255 #endif /* _INTEGRAL_MAX_BITS >= 64 */
256 
257 #endif /* _WSTAT_DEFINED */
258 
259 
260 /** Compatibility definitons *************************************************/
261 
262 #if !defined(RC_INVOKED)
263 
264 #ifdef _USE_32BIT_TIME_T
265  #define _fstat32 _fstat
266  #define _fstat32i64 _fstati64
267  #define _fstat64i32 _fstat64
268 #else
269  #define _fstat64i32 _fstat
270   __CRT_INLINE int __cdecl _fstat32(int _FileDes, struct _stat32 *_Stat)
271   {
272     struct _stat _Stat64;
273     int ret = _fstat(_FileDes, &_Stat64);
274     _Stat->st_dev = _Stat64.st_dev;
275     _Stat->st_ino = _Stat64.st_ino;
276     _Stat->st_mode = _Stat64.st_mode;
277     _Stat->st_nlink = _Stat64.st_nlink;
278     _Stat->st_uid = _Stat64.st_uid;
279     _Stat->st_gid = _Stat64.st_gid;
280     _Stat->st_rdev = _Stat64.st_rdev;
281     _Stat->st_size = _Stat64.st_size;
282     _Stat->st_atime = (__time32_t)_Stat64.st_atime;
283     _Stat->st_mtime = (__time32_t)_Stat64.st_mtime;
284     _Stat->st_ctime = (__time32_t)_Stat64.st_ctime;
285     return ret;
286   }
287   __CRT_INLINE int __cdecl _fstat32i64(int _FileDes, struct _stat32i64 *_Stat)
288   {
289     struct _stat64 _Stat64;
290     int ret = _fstat64(_FileDes, &_Stat64);
291     _Stat->st_dev = _Stat64.st_dev;
292     _Stat->st_ino = _Stat64.st_ino;
293     _Stat->st_mode = _Stat64.st_mode;
294     _Stat->st_nlink = _Stat64.st_nlink;
295     _Stat->st_uid = _Stat64.st_uid;
296     _Stat->st_gid = _Stat64.st_gid;
297     _Stat->st_rdev = _Stat64.st_rdev;
298     _Stat->st_size = _Stat64.st_size;
299     _Stat->st_atime = (__time32_t)_Stat64.st_atime;
300     _Stat->st_mtime = (__time32_t)_Stat64.st_mtime;
301     _Stat->st_ctime = (__time32_t)_Stat64.st_ctime;
302     return ret;
303   }
304 #endif /* _USE_32BIT_TIME_T */
305 
306 #endif /* !defined(RC_INVOKED) */
307 
308 #ifndef	NO_OLDNAMES
309 #define	_S_IFBLK	0x3000	/* Block: Is this ever set under w32? */
310 
311 #define S_IFMT _S_IFMT
312 #define S_IFDIR _S_IFDIR
313 #define S_IFCHR _S_IFCHR
314 #define S_IFREG _S_IFREG
315 #define S_IREAD _S_IREAD
316 #define S_IWRITE _S_IWRITE
317 #define S_IEXEC _S_IEXEC
318 #define	S_IFIFO		_S_IFIFO
319 #define	S_IFBLK		_S_IFBLK
320 
321 #define	_S_IRWXU	(_S_IREAD | _S_IWRITE | _S_IEXEC)
322 #define	_S_IXUSR	_S_IEXEC
323 #define	_S_IWUSR	_S_IWRITE
324 
325 #define	S_IRWXU		_S_IRWXU
326 #define	S_IXUSR		_S_IXUSR
327 #define	S_IWUSR		_S_IWUSR
328 #define	S_IRUSR		_S_IRUSR
329 #define	_S_IRUSR	_S_IREAD
330 
331 #define	S_ISDIR(m)	(((m) & S_IFMT) == S_IFDIR)
332 #define	S_ISFIFO(m)	(((m) & S_IFMT) == S_IFIFO)
333 #define	S_ISCHR(m)	(((m) & S_IFMT) == S_IFCHR)
334 #define	S_ISBLK(m)	(((m) & S_IFMT) == S_IFBLK)
335 #define	S_ISREG(m)	(((m) & S_IFMT) == S_IFREG)
336 
337 #if !defined (RC_INVOKED)
338   _CRTIMP int __cdecl stat(const char *_Filename,struct stat *_Stat);
339   _CRTIMP int __cdecl fstat(int _Desc,struct stat *_Stat);
340   _CRTIMP int __cdecl wstat(const wchar_t *_Filename,struct stat *_Stat);
341 __CRT_INLINE int __cdecl fstat(int _Desc,struct stat *_Stat) {
342   return _fstat(_Desc,(struct _stat *)_Stat);
343 }
344 
345 __CRT_INLINE int __cdecl stat(const char *_Filename,struct stat *_Stat) {
346   return _stat(_Filename,(struct _stat *)_Stat);
347 }
348 
349 __CRT_INLINE int __cdecl wstat(const wchar_t *_Filename,struct stat *_Stat) {
350   return _wstat(_Filename,(struct _stat *)_Stat);
351 }
352 
353 #endif
354 
355 #endif /* !NO_OLDNAMES */
356 
357 
358 #ifdef __cplusplus
359 }
360 #endif
361 
362 #pragma pack(pop)
363 #endif
364