source: Daodan/MinGW/include/sys/stat.h@ 1111

Last change on this file since 1111 was 1046, checked in by alloc, 8 years ago

Daodan: Added Windows MinGW and build batch file

File size: 16.9 KB
Line 
1/*
2 * stat.h
3 *
4 * Symbolic constants for opening and creating files, also stat, fstat and
5 * chmod functions.
6 *
7 * $Id: stat.h,v 4cf5070e9a04 2016/07/14 17:59:07 keithmarshall $
8 *
9 * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
10 * Copyright (C) 1997-2001, 2003-2005, 2007, 2016, MinGW.org Project.
11 *
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
19 *
20 * The above copyright notice, this permission notice, and the following
21 * disclaimer shall be included in all copies or substantial portions of
22 * the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
30 * DEALINGS IN THE SOFTWARE.
31 *
32 */
33#ifndef _SYS_STAT_H
34#pragma GCC system_header
35
36/* To support selective (partial) inclusion by <wchar.h>...
37 */
38#ifndef __WCHAR_H_SOURCED__
39/* ...we defer the definition of the normal multiple inclusion guard macro,
40 * until we know that this is NOT the <wchar.h> selective inclusion case.
41 */
42#define _SYS_STAT_H
43
44/* All MinGW headers are required to include <_mingw.h>; however, Microsoft
45 * also stipulate that USERS MUST include <sys/types.h>, BEFORE they include
46 * <sys/stat.h>. This is not only appallingly bad software engineering, on
47 * Microsoft's part, but it is a potential obstacle to portability of POSIX
48 * source code; (POSIX requires that <sys/stat.h> should be self-contained,
49 * with no requirement for any specific header inclusion order). Although
50 * it is more inclusive that POSIX requires, we may mitigate the deficiency
51 * inherent in Microsoft's poor software engineering, by simply including
52 * <sys/types.h> here; in so doing, we may also delegate the inclusion of
53 * <_mingw.h>, and the definition of all data types required herein, to...
54 */
55#include <sys/types.h>
56
57/* Constants for the st_mode member of struct stat, and its Microsoft
58 * specific variants.
59 */
60#define _S_IFIFO 0x1000 /* FIFO */
61#define _S_IFCHR 0x2000 /* Character */
62#define _S_IFDIR 0x4000 /* Directory */
63#define _S_IFREG 0x8000 /* Regular */
64
65#ifdef _MINGW_S_IFBLK_KLUDGE
66/* For preference, this kludge should NOT be enabled; for rationale,
67 * see: https://sourceforge.net/p/mingw/bugs/1146
68 *
69 * MS-Windows doesn't support testing for block special devices via the
70 * st_mode flags; ideally, client code to be ported to Windows should not
71 * blindly assume that S_IFBLK (or _S_IFBLK) is defined, but should rather
72 * check for it, and compile dependent code conditionally. Notwithstanding,
73 * this kludge allows the user to force a definition, which we arbitrarily
74 * choose to ensure that S_ISBLK (or _S_ISBLK) always returns FALSE, (i.e.
75 * choose a value such that _S_IFBLK & _S_IFMT can NEVER equal _S_IFBLK).
76 */
77#define _S_IFBLK 0x3001 /* Block: unsupported on Win32 */
78#endif
79
80#define _S_IFMT 0xF000 /* File type mask */
81
82#define _S_IEXEC 0x0040
83#define _S_IWRITE 0x0080
84#define _S_IREAD 0x0100
85
86#define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
87#define _S_IXUSR _S_IEXEC
88#define _S_IWUSR _S_IWRITE
89#define _S_IRUSR _S_IREAD
90
91#define _S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
92#define _S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
93#define _S_ISCHR(m) (((m) & _S_IFMT) == _S_IFCHR)
94#define _S_ISBLK(m) (((m) & _S_IFMT) == _S_IFBLK)
95#define _S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
96
97#ifndef _NO_OLDNAMES
98
99#define S_IFIFO _S_IFIFO
100#define S_IFCHR _S_IFCHR
101#ifdef _S_IFBLK
102#define S_IFBLK _S_IFBLK
103#endif
104#define S_IFDIR _S_IFDIR
105#define S_IFREG _S_IFREG
106#define S_IFMT _S_IFMT
107#define S_IEXEC _S_IEXEC
108#define S_IWRITE _S_IWRITE
109#define S_IREAD _S_IREAD
110#define S_IRWXU _S_IRWXU
111#define S_IXUSR _S_IXUSR
112#define S_IWUSR _S_IWUSR
113#define S_IRUSR _S_IRUSR
114
115#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
116#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
117#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
118#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
119#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
120
121#endif /* !_NO_OLDNAMES */
122
123#ifndef _S_IFBLK
124/* When the _S_IFBLK kludge is NOT enabled, (as it ideally should not be),
125 * ensure that any attempt to use its dependent macros is denied...
126 */
127# pragma GCC poison _S_ISBLK
128
129# if defined _NO_UNSUPPORTED || defined _NO_OLDNAMES
130 /* ...including that for the standard POSIX macro, when unsupported
131 * features, or Microsoft's old names, are explicitly forbidden...
132 */
133# pragma GCC poison S_ISBLK
134
135# else /* !(_NO_UNSUPPORTED || _NO_OLDNAMES) */
136 /* ...otherwise assume that the kludge is automatically enabled with
137 * respect to S_ISBLK, (because GCC gratuitously misuses it).
138 */
139# define S_IFBLK 0x3001 /* Block: unsupported on Win32 */
140
141# endif /* !(_NO_UNSUPPORTED || _NO_OLDNAMES) */
142#endif /* !_S_IFBLK */
143#endif /* !__WCHAR_H_SOURCED__ */
144
145#ifndef RC_INVOKED
146#ifndef __struct_stat_defined
147/* The structure manipulated and returned by stat() and fstat(); note that
148 * expansion of the macro provided below will yield variants of struct stat
149 * to conform with Microsoft's usage, (and POSIX usage up to and including
150 * POSIX.1-2001, but NOT the extended specification of POSIX.1-2008).
151 *
152 * NOTE: If called on a directory the values in the time fields are not only
153 * invalid, they will cause localtime et. al. to return NULL. And calling
154 * asctime with a NULL pointer causes an Invalid Page Fault. So watch it!
155 */
156#define __struct_stat_defined(__st_off_t, __st_time_t) \
157{ _dev_t st_dev; /* Equivalent to drive number 0=A 1=B ... */ \
158 _ino_t st_ino; /* Always zero ? */ \
159 _mode_t st_mode; /* See above constants */ \
160 short st_nlink; /* Number of links. */ \
161 short st_uid; /* User: Maybe significant on NT ? */ \
162 short st_gid; /* Group: Ditto */ \
163 _dev_t st_rdev; /* Seems useless (not even filled in) */ \
164 __st_off_t st_size; /* File size in bytes */ \
165 __st_time_t st_atime; /* Access time (always 00:00 on FAT) */ \
166 __st_time_t st_mtime; /* Modified time */ \
167 __st_time_t st_ctime; /* Creation time */ \
168}
169
170/* Here, we expand the preceding macro to yield the actual definition
171 * of struct stat, under its current Microsoft "uglified" name...
172 */
173struct _stat __struct_stat_defined( _off_t, time_t );
174
175#ifndef _NO_OLDNAMES
176/* ...while this alternative expansion yields its standard POSIX name,
177 * (and its original Microsoft name); apart from its name, this must be
178 * defined identically to struct _stat above.
179 */
180struct stat __struct_stat_defined( _off_t, time_t );
181#endif /* !_NO_OLDNAMES */
182
183#if defined __MSVCRT__
184/* This variant of struct stat is required to support the use of the
185 * _stati64() function, which is provided by MSVCRT.DLL, but was not
186 * present in CRTDLL.DLL...
187 */
188struct _stati64 __struct_stat_defined( __off64_t, time_t );
189
190#if __MSVCRT_VERSION__ >= __MSVCR61_DLL || _WIN32_WINNT >= _WIN32_WINNT_WIN2K
191/* ...while this supports the use of the _stat64() function, introduced
192 * by MSVCR61.DLL, and subsequently added to MSVCRT.DLL for releases from
193 * Win2K onwards...
194 */
195struct __stat64 __struct_stat_defined( __off64_t, __time64_t );
196
197#if __MSVCRT_VERSION__ >= __MSVCR80_DLL
198/* ...and these are specific to additional function variants, added to
199 * the non-free MSVCR80.DLL, and its later derivatives, but not present
200 * in MSVCRT.DLL (or CRTDLL.DLL).
201 */
202struct __stat32 __struct_stat_defined( __off32_t, __time32_t );
203struct _stat32i64 __struct_stat_defined( __off64_t, __time32_t );
204struct _stat64i32 __struct_stat_defined( __off32_t, __time64_t );
205
206#endif /* __MSVCRT_VERSION__ >= __MSVCR80_DLL */
207#endif /* __MSVCRT_VERSION__ >= __MSVCR61_DLL */
208#endif /* __MSVCRT__ */
209
210/* From here on, it is sufficient to leave __struct_stat_defined as
211 * a macro which expands to nothing.
212 */
213#undef __struct_stat_defined
214#define __struct_stat_defined
215
216#endif /* !__struct_stat_defined */
217
218_BEGIN_C_DECLS
219
220#ifdef _SYS_STAT_H
221/* This set of function prototypes are to be declared only when
222 * <sys/stat.h> is included directly.
223 */
224_CRTIMP __cdecl __MINGW_NOTHROW int _umask (int);
225_CRTIMP __cdecl __MINGW_NOTHROW int _chmod (const char *, int);
226
227#if __MSVCRT_VERSION__ < __MSVCR80_DLL
228/* This pair of functions are present in all versions of MSVCRT.DLL, but
229 * they are NOT present in MSVCR80.DLL, nor in any of its later non-free
230 * variants, all of which rely on inline aliases (defined below).
231 */
232_CRTIMP __cdecl __MINGW_NOTHROW int _fstat (int, struct _stat *);
233_CRTIMP __cdecl __MINGW_NOTHROW int _stat (const char *, struct _stat *);
234#endif /* __MSVCRT_VERSION__ < __MSVCR80_DLL */
235
236#ifndef _NO_OLDNAMES
237/* These are the standard POSIX names, (and the original Microsoft names),
238 * for the preceding four functions.
239 */
240_CRTIMP __cdecl __MINGW_NOTHROW int umask (int);
241_CRTIMP __cdecl __MINGW_NOTHROW int chmod (const char *, int);
242
243#if __MSVCRT_VERSION__ < __MSVCR80_DLL
244/* Since the underlying functions, with "uglified" names, are not supported
245 * by MSVCR80.DLL and its later derivitaves, there is also nothing to which
246 * to map these originally named alternatives; declare prototypes only when
247 * using DLL versions which can support them, while falling back to the use
248 * of inline replacements (defined below) in the unsupported cases.
249 */
250_CRTIMP __cdecl __MINGW_NOTHROW int fstat (int, struct stat *);
251_CRTIMP __cdecl __MINGW_NOTHROW int stat (const char *, struct stat *);
252#endif /* __MSVCRT_VERSION__ < __MSVCR80_DLL */
253#endif /* !_NO_OLDNAMES */
254
255#if defined __MSVCRT__
256#if __MSVCRT_VERSION__ < __MSVCR80_DLL
257/* This pair of functions were withdrawn from MSVCR80.DLL, and its later
258 * derivatives, but remain in all versions of MSVCRT.DLL
259 */
260_CRTIMP __cdecl __MINGW_NOTHROW int _fstati64 (int, struct _stati64 *);
261_CRTIMP __cdecl __MINGW_NOTHROW int _stati64 (const char *, struct _stati64 *);
262#endif /* __MSVCRT_VERSION__ < __MSVCR80_DLL */
263
264#if __MSVCRT_VERSION__ >= __MSVCR61_DLL || _WIN32_WINNT >= _WIN32_WINNT_WIN2K
265/* This pair of functions were introduced in MSVCR61.DLL, and were subsequently
266 * added to MSVCRT.DLL from the release accompanying Win2K onwards...
267 */
268_CRTIMP __cdecl __MINGW_NOTHROW int _fstat64 (int, struct __stat64 *);
269_CRTIMP __cdecl __MINGW_NOTHROW int _stat64 (const char *, struct __stat64 *);
270
271#if __MSVCRT_VERSION__ >= __MSVCR80_DLL
272/* ...whereas this group were introduced in MSVCR80.DLL, and its later
273 * derivatives, but are not present in MSVCRT.DLL
274 */
275_CRTIMP __cdecl __MINGW_NOTHROW int _fstat32 (int, struct __stat32 *);
276_CRTIMP __cdecl __MINGW_NOTHROW int _stat32 (const char *, struct __stat32 *);
277_CRTIMP __cdecl __MINGW_NOTHROW int _fstat32i64 (int, struct _stat32i64 *);
278_CRTIMP __cdecl __MINGW_NOTHROW int _fstat64i32 (int, struct _stat64i32 *);
279_CRTIMP __cdecl __MINGW_NOTHROW int _stat32i64 (const char *, struct _stat32i64 *);
280_CRTIMP __cdecl __MINGW_NOTHROW int _stat64i32 (const char *, struct _stat64i32 *);
281
282#ifdef _USE_32BIT_TIME_T
283/* We must provide inline replacements for the four MSVCRT.DLL functions
284 * which have been withdrawn from MSVCR80.DLL, and its later derivatives;
285 * this first set of replacements are compatible with their MSVCRT.DLL
286 * equivalents, but require the user to define _USE_32BIT_TIME_T...
287 */
288__CRT_ALIAS __cdecl __MINGW_NOTHROW int _fstat (int __v1, struct _stat *__v2)
289 { return _fstat32 (__v1, (struct __stat32 *)(__v2)); }
290
291__CRT_ALIAS __cdecl __MINGW_NOTHROW int _stat (const char *__v1, struct _stat *__v2)
292 { return _stat32 (__v1, (struct __stat32 *)(__v2)); }
293
294__CRT_ALIAS __cdecl __MINGW_NOTHROW int _fstati64 (int __v1, struct _stati64 *__v2)
295 { return _fstat32i64 (__v1, (struct _stat32i64 *)(__v2)); }
296
297__CRT_ALIAS __cdecl __MINGW_NOTHROW int _stati64 (const char *__v1, struct _stati64 *__v2)
298 { return _stat32i64 (__v1, (struct _stat32i64 *)(__v2)); }
299
300#else /* !_USE_32BIT_TIME_T */
301/* ...whereas, the following alternatives emulate the brain-damaged
302 * behaviour of Microsoft's own implementations, which take effect when
303 * the user does not define _USE_32BIT_TIME_T; they break compatibility
304 * with MSVCRT.DLL
305 */
306__CRT_ALIAS __cdecl __MINGW_NOTHROW int _fstat (int __v1, struct _stat *__v2)
307 { return _fstat64i32 (__v1, (struct _stat64i32 *)(__v2)); }
308
309__CRT_ALIAS __cdecl __MINGW_NOTHROW int _stat (const char *__v1, struct _stat *__v2)
310 { return _stat64i32 (__v1, (struct _stat64i32 *)(__v2)); }
311
312__CRT_ALIAS __cdecl __MINGW_NOTHROW int _fstati64 (int __v1, struct _stati64 *__v2)
313 { return _fstat64 (__v1, (struct __stat64 *)(__v2)); }
314
315__CRT_ALIAS __cdecl __MINGW_NOTHROW int _stati64 (const char *__v1, struct _stati64 *__v2)
316 { return _stat64 (__v1,(struct __stat64*)(__v2)); }
317#endif /* !_USE_32BIT_TIME_T */
318
319#ifndef _NO_OLDNAMES
320/* Irrespective of the state of _USE_32BIT_TIME_T, we may provide inline
321 * replacements for the stat() and fstat() functions, (which are missing
322 * from MSVCR80.DLL and its later derivatives), simply by aliasing them
323 * to their corresponding replacements with "uglified" names.
324 */
325__CRT_ALIAS __cdecl __MINGW_NOTHROW int fstat (int __v1, struct _stat *__v2)
326 { return _fstat (__v1, __v2); }
327
328__CRT_ALIAS __cdecl __MINGW_NOTHROW int stat (const char *__v1, struct _stat *__v2)
329 { return _stat (__v1, __v2); }
330
331#endif /* !_NO_OLDNAMES */
332#endif /* __MSVCRT_VERSION__ >= __MSVCR80_DLL */
333#endif /* __MSVCRT_VERSION__ >= __MSVCR61_DLL */
334#endif /* __MSVCRT__ */
335#endif /* _SYS_STAT_H */
336
337#if defined __MSVCRT__ && !(defined _SYS_STAT_H && defined _WCHAR_H)
338/* This final group of function prototypes, specific to MSVCRT.DLL and its
339 * non-free derivatives, are to be declared both when <sys/stat.h> is included
340 * directly, and when it is selectively included by <wchar.h>; however, if both
341 * _SYS_STAT_H and _WCHAR_H are defined, by the time we get to here, then this
342 * must be the direct inclusion case, after having already declared these via
343 * selective inclusion by <wchar.h>, and we should not declare these again;
344 * (in particular, we should not repeat inline function implementations).
345 */
346#if __MSVCRT_VERSION__ < __MSVCR80_DLL
347/* As is the case for their regular counterparts, this pair of functions
348 * remain available in MSVCRT.DLL itself, but they are not exported from its
349 * non-free derivatives from MSVCR80.DLL onwards, whence it is expected that
350 * they will be replaced by inline implementations.
351 */
352_CRTIMP __cdecl __MINGW_NOTHROW int _wstat(const wchar_t *, struct _stat *);
353_CRTIMP __cdecl __MINGW_NOTHROW int _wstati64 (const wchar_t *, struct _stati64 *);
354#endif /* __MSVCRT_VERSION__ < __MSVCR80_DLL */
355
356#if __MSVCRT_VERSION__ >= __MSVCR61_DLL || _WIN32_WINNT >= _WIN32_WINNT_WIN2K
357/* Similarly, this variant was introduced in MSVCR80.DLL, and was subsequently
358 * added to MSVCRT.DLL with the release of Win2K...
359 */
360_CRTIMP __cdecl __MINGW_NOTHROW int _wstat64 (const wchar_t *, struct __stat64 *);
361
362#if __MSVCRT_VERSION__ >= __MSVCR80_DLL
363/* ...whereas these variants are exclusive to the non-free MSVCR80.DLL, and
364 * its later derivatives; they are not available in MSVCRT.DLL.
365 */
366_CRTIMP __cdecl __MINGW_NOTHROW int _wstat32 (const wchar_t *, struct __stat32 *);
367_CRTIMP __cdecl __MINGW_NOTHROW int _wstat32i64 (const wchar_t *, struct _stat32i64 *);
368_CRTIMP __cdecl __MINGW_NOTHROW int _wstat64i32 (const wchar_t *, struct _stat64i32 *);
369
370#ifdef _USE_32BIT_TIME_T
371/* Once again, we must furnish inline replacements for the functions which
372 * were withdrawn from MSVCR80.DLL and its later derivatives; these are the
373 * implementations which remain compatible with MSVCRT.DLL, but require the
374 * user to define _USE_32BIT_TIME_T...
375 */
376__CRT_ALIAS __cdecl __MINGW_NOTHROW int _wstat (const wchar_t *__v1, struct _stat *__v2)
377 { return _wstat32 (__v1, (struct __stat32 *)(__v2)); }
378
379__CRT_ALIAS __cdecl __MINGW_NOTHROW int _wstati64 (const wchar_t *__v1, struct _stati64 *__v2)
380 { return _wstat32i64 (__v1, (struct _stat32i64 *)(__v2)); }
381
382#else /* !_USE_32BIT_TIME_T */
383/* ...whereas these emulate the brain-damaged Microsoft behaviour, for the
384 * case when the user does not define _USE_32BIT_TIME_T, breaking MSVCRT.DLL
385 * compatibility.
386 */
387__CRT_ALIAS __cdecl __MINGW_NOTHROW int _wstat (const wchar_t *__v1, struct _stat *__v2)
388 { return _wstat64i32 (__v1, (struct _stat64i32 *)(__v2)); }
389
390__CRT_ALIAS __cdecl __MINGW_NOTHROW int _wstati64 (const wchar_t *__v1, struct _stati64 *__v2)
391 { return _wstat64 (__v1, (struct __stat64 *)(__v2)); }
392
393#endif /* !_USE_32BIT_TIME_T */
394#endif /* __MSVCRT_VERSION__ >= 0x0800 */
395#endif /* __MSVCRT_VERSION__ >= 0x0601 */
396#endif /* __MSVCRT__ && !(_SYS_STAT_H && _WCHAR_H) */
397
398_END_C_DECLS
399
400#endif /* ! RC_INVOKED */
401#endif /* !_SYS_STAT__H: $RCSfile: stat.h,v $: end of file */
Note: See TracBrowser for help on using the repository browser.