OSDN Git Service

b39a792c8e6d09e199a6a90c76961a1faf017c08
[mingw/mingw-org-wsl.git] / include / sys / stat.h
1 /**
2  * @file stat.h
3  * @copy 2012 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 #ifndef _STAT_H_
25 #define _STAT_H_
26
27 /* All the headers include this file. */
28 #include <_mingw.h>
29
30 #define __need_size_t
31 #define __need_wchar_t
32 #ifndef RC_INVOKED
33 #include <stddef.h>
34 #endif /* Not RC_INVOKED */
35
36 #include <sys/types.h>
37
38 /*
39  * Constants for the stat st_mode member.
40  */
41 #define _S_IFIFO        0x1000  /* FIFO */
42 #define _S_IFCHR        0x2000  /* Character */
43 #define _S_IFBLK        0x3000  /* Block: Is this ever set under w32? */
44 #define _S_IFDIR        0x4000  /* Directory */
45 #define _S_IFREG        0x8000  /* Regular */
46
47 #define _S_IFMT         0xF000  /* File type mask */
48
49 #define _S_IEXEC        0x0040
50 #define _S_IWRITE       0x0080
51 #define _S_IREAD        0x0100
52
53 #define _S_IRWXU        (_S_IREAD | _S_IWRITE | _S_IEXEC)
54 #define _S_IXUSR        _S_IEXEC
55 #define _S_IWUSR        _S_IWRITE
56 #define _S_IRUSR        _S_IREAD
57
58 #define _S_ISDIR(m)     (((m) & _S_IFMT) == _S_IFDIR)
59 #define _S_ISFIFO(m)    (((m) & _S_IFMT) == _S_IFIFO)
60 #define _S_ISCHR(m)     (((m) & _S_IFMT) == _S_IFCHR)
61 #define _S_ISBLK(m)     (((m) & _S_IFMT) == _S_IFBLK)
62 #define _S_ISREG(m)     (((m) & _S_IFMT) == _S_IFREG)
63
64 #ifndef _NO_OLDNAMES
65
66 #define S_IFIFO         _S_IFIFO
67 #define S_IFCHR         _S_IFCHR
68 #define S_IFBLK         _S_IFBLK
69 #define S_IFDIR         _S_IFDIR
70 #define S_IFREG         _S_IFREG
71 #define S_IFMT          _S_IFMT
72 #define S_IEXEC         _S_IEXEC
73 #define S_IWRITE        _S_IWRITE
74 #define S_IREAD         _S_IREAD
75 #define S_IRWXU         _S_IRWXU
76 #define S_IXUSR         _S_IXUSR
77 #define S_IWUSR         _S_IWUSR
78 #define S_IRUSR         _S_IRUSR
79
80 #define S_ISDIR(m)      (((m) & S_IFMT) == S_IFDIR)
81 #define S_ISFIFO(m)     (((m) & S_IFMT) == S_IFIFO)
82 #define S_ISCHR(m)      (((m) & S_IFMT) == S_IFCHR)
83 #define S_ISBLK(m)      (((m) & S_IFMT) == S_IFBLK)
84 #define S_ISREG(m)      (((m) & S_IFMT) == S_IFREG)
85
86 #endif  /* Not _NO_OLDNAMES */
87
88 #ifndef RC_INVOKED
89
90 #ifndef _STAT_DEFINED
91 /*
92  * The structure manipulated and returned by stat and fstat.
93  *
94  * NOTE: If called on a directory the values in the time fields are not only
95  * invalid, they will cause localtime et. al. to return NULL. And calling
96  * asctime with a NULL pointer causes an Invalid Page Fault. So watch it!
97  */
98 struct _stat
99 {
100         _dev_t  st_dev;         /* Equivalent to drive number 0=A 1=B ... */
101         _ino_t  st_ino;         /* Always zero ? */
102         _mode_t st_mode;        /* See above constants */
103         short   st_nlink;       /* Number of links. */
104         short   st_uid;         /* User: Maybe significant on NT ? */
105         short   st_gid;         /* Group: Ditto */
106         _dev_t  st_rdev;        /* Seems useless (not even filled in) */
107         _off_t  st_size;        /* File size in bytes */
108         time_t  st_atime;       /* Accessed date (always 00:00 hrs local
109                                  * on FAT) */
110         time_t  st_mtime;       /* Modified time */
111         time_t  st_ctime;       /* Creation time */
112 };
113
114 #ifndef _NO_OLDNAMES
115 /* NOTE: Must be the same as _stat above. */
116 struct stat
117 {
118         dev_t   st_dev;         /* Equivalent to drive number 0=A 1=B ... */
119         ino_t   st_ino;         /* Always zero ? */
120         mode_t  st_mode;        /* See above constants */
121         short   st_nlink;       /* Number of links. */
122         short   st_uid;         /* User: Maybe significant on NT ? */
123         short   st_gid;         /* Group: Ditto */
124         dev_t   st_rdev;        /* Seems useless (not even filled in) */
125         off_t   st_size;        /* File size in bytes */
126         time_t  st_atime;       /* Accessed date (always 00:00 hrs local
127                                  * on FAT) */
128         time_t  st_mtime;       /* Modified time */
129         time_t  st_ctime;       /* Creation time */
130 };
131 #endif /* _NO_OLDNAMES */
132
133 struct _stati64 {
134     _dev_t st_dev;
135     _ino_t st_ino;
136     _mode_t st_mode;
137     short st_nlink;
138     short st_uid;
139     short st_gid;
140     _dev_t st_rdev;
141     __int64 st_size;
142     time_t st_atime;
143     time_t st_mtime;
144     time_t st_ctime;
145 };
146 #if __MSVCRT_VERSION__ >= 0x0601
147 struct __stat64
148 {
149     _dev_t st_dev;
150     _ino_t st_ino;
151     _mode_t st_mode;
152     short st_nlink;
153     short st_uid;
154     short st_gid;
155     _dev_t st_rdev;
156     __int64 st_size;
157     __time64_t st_atime;
158     __time64_t st_mtime;
159     __time64_t st_ctime;
160 };
161 #endif /* __MSVCRT_VERSION__ >= 0x0601 */
162 #if __MSVCRT_VERSION__ >= 0x0800
163 struct __stat32
164 {
165         _dev_t          st_dev;
166         _ino_t          st_ino;
167         _mode_t         st_mode;
168         short           st_nlink;
169         short           st_uid;
170         short           st_gid;
171         _dev_t          st_rdev;
172         __int32         st_size;
173         __time32_t      st_atime;
174         __time32_t      st_mtime;
175         __time32_t      st_ctime;
176 };
177 struct _stat32i64 {
178         _dev_t          st_dev;
179         _ino_t          st_ino;
180         _mode_t         st_mode;
181         short           st_nlink;
182         short           st_uid;
183         short           st_gid;
184         _dev_t          st_rdev;
185         __int64         st_size;
186         __time32_t      st_atime;
187         __time32_t      st_mtime;
188         __time32_t      st_ctime;
189 };
190 struct _stat64i32 {
191         _dev_t          st_dev;
192         _ino_t          st_ino;
193         _mode_t         st_mode;
194         short           st_nlink;
195         short           st_uid;
196         short           st_gid;
197         _dev_t          st_rdev;
198         __int32         st_size;
199         __time64_t      st_atime;
200         __time64_t      st_mtime;
201         __time64_t      st_ctime;
202 };
203 #endif /* __MSVCRT_VERSION__ >= 0x0800 */
204 #define _STAT_DEFINED
205 #endif /* _STAT_DEFINED */
206
207 #ifdef  __cplusplus
208 extern "C" {
209 #endif
210
211 #if __MSVCRT_VERSION__ < 0x0800
212 _CRTIMP int __cdecl __MINGW_NOTHROW     _fstat (int, struct _stat*);
213 #endif
214 _CRTIMP int __cdecl __MINGW_NOTHROW     _chmod (const char*, int);
215 #if __MSVCRT_VERSION__ < 0x0800
216 _CRTIMP int __cdecl __MINGW_NOTHROW     _stat (const char*, struct _stat*);
217 #endif
218
219 #ifndef _NO_OLDNAMES
220 /* FIXME for __MSVCRT_VERSION__ >= 0x0800 */
221 /* These functions live in liboldnames.a. */
222 _CRTIMP int __cdecl __MINGW_NOTHROW     fstat (int, struct stat*);
223 _CRTIMP int __cdecl __MINGW_NOTHROW     chmod (const char*, int);
224 _CRTIMP int __cdecl __MINGW_NOTHROW     stat (const char*, struct stat*);
225
226 #endif  /* Not _NO_OLDNAMES */
227
228 #if __MSVCRT_VERSION__ < 0x0800
229 _CRTIMP int __cdecl __MINGW_NOTHROW  _fstati64(int, struct _stati64 *);
230 _CRTIMP int __cdecl __MINGW_NOTHROW  _stati64(const char *, struct _stati64 *);
231 #endif
232 /* These require newer versions of msvcrt.dll (6.10 or higher).  */ 
233 #if __MSVCRT_VERSION__ >= 0x0601
234 _CRTIMP int __cdecl __MINGW_NOTHROW _fstat64 (int, struct __stat64*);
235 _CRTIMP int __cdecl __MINGW_NOTHROW _stat64 (const char*, struct __stat64*);
236 #endif /* __MSVCRT_VERSION__ >= 0x0601 */
237 #if __MSVCRT_VERSION__ >= 0x0800
238 _CRTIMP int __cdecl __MINGW_NOTHROW     _fstat32 (int, struct __stat32*);
239 _CRTIMP int __cdecl __MINGW_NOTHROW     _stat32 (const char*, struct __stat32*);
240 _CRTIMP int __cdecl __MINGW_NOTHROW     _fstat32i64 (int, struct _stat32i64*);
241 _CRTIMP int __cdecl __MINGW_NOTHROW     _fstat64i32 (int, struct _stat64i32*);
242 _CRTIMP int __cdecl __MINGW_NOTHROW     _stat32i64 (const char*, struct _stat32i64*);
243 _CRTIMP int __cdecl __MINGW_NOTHROW     _stat64i32 (const char*, struct _stat64i32*);
244 #ifndef _USE_32BIT_TIME_T
245 _CRTALIAS int __cdecl __MINGW_NOTHROW   _fstat (int _v1, struct _stat* _v2)              { return(_fstat64i32 (_v1,(struct _stat64i32*)_v2)); }
246 _CRTALIAS int __cdecl __MINGW_NOTHROW   _stat (const char* _v1, struct _stat* _v2)       { return(_stat64i32  (_v1,(struct _stat64i32*)_v2)); }
247 _CRTALIAS int __cdecl __MINGW_NOTHROW   _fstati64 (int _v1, struct _stati64* _v2)        { return(_fstat64 (_v1,(struct __stat64*)_v2)); }
248 _CRTALIAS int __cdecl __MINGW_NOTHROW   _stati64 (const char* _v1, struct _stati64* _v2) { return(_stat64  (_v1,(struct __stat64*)_v2)); }
249 #else
250 _CRTALIAS int __cdecl __MINGW_NOTHROW   _fstat (int _v1, struct _stat* _v2)              { return(_fstat32 (_v1,(struct __stat32*)_v2)); }
251 _CRTALIAS int __cdecl __MINGW_NOTHROW   _stat (const char* _v1, struct _stat* _v2)       { return(_stat32  (_v1,(struct __stat32*)_v2)); }
252 _CRTALIAS int __cdecl __MINGW_NOTHROW   _fstati64 (int _v1, struct _stati64* _v2)        { return(_fstat32i64 (_v1,(struct _stat32i64*)_v2)); }
253 _CRTALIAS int __cdecl __MINGW_NOTHROW   _stati64 (const char* _v1, struct _stati64* _v2) { return(_stat32i64  (_v1,(struct _stat32i64*)_v2)); }
254 #endif /* !_USE_32BIT_TIME_T */
255 #endif /* __MSVCRT_VERSION__ >= 0x0800 */
256
257
258 #if !defined ( _WSTAT_DEFINED) /* also declared in wchar.h */
259 #if __MSVCRT_VERSION__ < 0x0800
260 _CRTIMP int __cdecl __MINGW_NOTHROW     _wstat(const wchar_t*, struct _stat*);
261 _CRTIMP int __cdecl __MINGW_NOTHROW     _wstati64 (const wchar_t*, struct _stati64*);
262 #endif
263 #if __MSVCRT_VERSION__ >= 0x0601
264 _CRTIMP int __cdecl __MINGW_NOTHROW _wstat64 (const wchar_t*, struct __stat64*);
265 #endif /* __MSVCRT_VERSION__ >= 0x0601 */
266 #if __MSVCRT_VERSION__ >= 0x0800
267 _CRTIMP int __cdecl __MINGW_NOTHROW     _wstat32 (const wchar_t*, struct __stat32*);
268 _CRTIMP int __cdecl __MINGW_NOTHROW     _wstat32i64 (const wchar_t*, struct _stat32i64*);
269 _CRTIMP int __cdecl __MINGW_NOTHROW     _wstat64i32 (const wchar_t*, struct _stat64i32*);
270 #ifndef _USE_32BIT_TIME_T
271 _CRTALIAS int __cdecl __MINGW_NOTHROW   _wstat (const wchar_t* _v1, struct _stat* _v2)       { return(_wstat64i32 (_v1,(struct _stat64i32*)_v2)); }
272 _CRTALIAS int __cdecl __MINGW_NOTHROW   _wstati64 (const wchar_t* _v1, struct _stati64* _v2) { return(_wstat64 (_v1,(struct __stat64*)_v2)); }
273 #else
274 _CRTALIAS int __cdecl __MINGW_NOTHROW   _wstat (const wchar_t* _v1, struct _stat* _v2)       { return(_wstat32 (_v1,(struct __stat32*)_v2)); }
275 _CRTALIAS int __cdecl __MINGW_NOTHROW   _wstati64 (const wchar_t* _v1, struct _stati64* _v2) { return(_wstat32i64 (_v1,(struct _stat32i64*)_v2)); }
276 #endif /* !_USE_32BIT_TIME_T */
277 #endif /* __MSVCRT_VERSION__ >= 0x0800 */
278 #define _WSTAT_DEFINED
279 #endif /* _WSTAT_DEFIND */
280
281 #ifdef  __cplusplus
282 }
283 #endif
284
285 #endif  /* Not RC_INVOKED */
286
287 #endif  /* Not _STAT_H_ */