master
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
19extern "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 _CRTIMP int __cdecl _fstat64i32(int _FileDes,struct _stat64i32 *_Stat);
74 _CRTIMP int __cdecl _stat64(const char *_Name,struct _stat64 *_Stat);
75 _CRTIMP int __cdecl _stat32i64(const char *_Name,struct _stat32i64 *_Stat);
76 _CRTIMP int __cdecl _stat64i32(const char *_Name,struct _stat64i32 *_Stat);
77
78#ifndef _WSTAT_DEFINED
79#define _WSTAT_DEFINED
80 _CRTIMP int __cdecl _wstat32(const wchar_t *_Name,struct _stat32 *_Stat);
81 _CRTIMP int __cdecl _wstat32i64(const wchar_t *_Name,struct _stat32i64 *_Stat);
82 _CRTIMP int __cdecl _wstat64i32(const wchar_t *_Name,struct _stat64i32 *_Stat);
83 _CRTIMP int __cdecl _wstat64(const wchar_t *_Name,struct _stat64 *_Stat);
84#endif
85
86#ifndef NO_OLDNAMES
87#define _S_IFBLK 0x6000 /* Block: Is this ever set under w32? */
88
89#define S_IFMT _S_IFMT
90#define S_IFDIR _S_IFDIR
91#define S_IFCHR _S_IFCHR
92#define S_IFREG _S_IFREG
93#define S_IREAD _S_IREAD
94#define S_IWRITE _S_IWRITE
95#define S_IEXEC _S_IEXEC
96#define S_IFIFO _S_IFIFO
97#define S_IFBLK _S_IFBLK
98
99#define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
100#define _S_IXUSR _S_IEXEC
101#define _S_IWUSR _S_IWRITE
102
103#define S_IRWXU _S_IRWXU
104#define S_IXUSR _S_IXUSR
105#define S_IWUSR _S_IWUSR
106#define S_IRUSR _S_IRUSR
107#define _S_IRUSR _S_IREAD
108
109#define S_IRGRP (S_IRUSR >> 3)
110#define S_IWGRP (S_IWUSR >> 3)
111#define S_IXGRP (S_IXUSR >> 3)
112#define S_IRWXG (S_IRWXU >> 3)
113
114#define S_IROTH (S_IRGRP >> 3)
115#define S_IWOTH (S_IWGRP >> 3)
116#define S_IXOTH (S_IXGRP >> 3)
117#define S_IRWXO (S_IRWXG >> 3)
118
119#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
120#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
121#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
122#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
123#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
124
125#endif
126
127#if !defined(NO_OLDNAMES) || defined(_POSIX)
128
129/*
130 * When building mingw-w64 CRT files it is required that the fstat, stat and
131 * wstat functions are not declared with __MINGW_ASM_CALL redirection.
132 * Otherwise the mingw-w64 would provide broken fstat, stat and wstat symbols.
133 * To prevent ABI issues, the mingw-w64 runtime should not call the fstat,
134 * stat and wstat functions, instead it should call the fixed-size variants.
135 */
136#ifndef _CRTBLD
137struct stat {
138 _dev_t st_dev;
139 _ino_t st_ino;
140 unsigned short st_mode;
141 short st_nlink;
142 short st_uid;
143 short st_gid;
144 _dev_t st_rdev;
145 off_t st_size; /* off_t follows _FILE_OFFSET_BITS */
146 time_t st_atime; /* time_t follows _USE_32BIT_TIME_T */
147 time_t st_mtime;
148 time_t st_ctime;
149};
150#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
151#ifdef _USE_32BIT_TIME_T
152int __cdecl fstat(int _Desc, struct stat *_Stat) __MINGW_ASM_CALL(_fstat32i64);
153int __cdecl stat(const char *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(stat32i64);
154int __cdecl wstat(const wchar_t *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(wstat32i64);
155#else
156int __cdecl fstat(int _Desc, struct stat *_Stat) __MINGW_ASM_CALL(_fstat64);
157int __cdecl stat(const char *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(stat64);
158int __cdecl wstat(const wchar_t *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(wstat64);
159#endif
160#else
161#ifdef _USE_32BIT_TIME_T
162int __cdecl fstat(int _Desc, struct stat *_Stat) __MINGW_ASM_CALL(_fstat32);
163int __cdecl stat(const char *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(stat32);
164int __cdecl wstat(const wchar_t *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(wstat32);
165#else
166int __cdecl fstat(int _Desc, struct stat *_Stat) __MINGW_ASM_CALL(_fstat64i32);
167int __cdecl stat(const char *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(stat64i32);
168int __cdecl wstat(const wchar_t *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(wstat64i32);
169#endif
170#endif
171#endif
172
173struct stat64 {
174 _dev_t st_dev;
175 _ino_t st_ino;
176 unsigned short st_mode;
177 short st_nlink;
178 short st_uid;
179 short st_gid;
180 _dev_t st_rdev;
181 __MINGW_EXTENSION __int64 st_size;
182 __time64_t st_atime;
183 __time64_t st_mtime;
184 __time64_t st_ctime;
185};
186int __cdecl fstat64(int _Desc, struct stat64 *_Stat);
187int __cdecl stat64(const char *_Filename, struct stat64 *_Stat);
188int __cdecl wstat64(const wchar_t *_Filename, struct stat64 *_Stat);
189
190#endif
191
192#ifdef __cplusplus
193}
194#endif
195
196#pragma pack(pop)
197
198#endif /* _INC_STAT */
199