Home | History | Annotate | Download | only in sys
      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
     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 #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   int __cdecl _fstat64i32(int _FileDes,struct _stat64i32 *_Stat);
     74 #ifndef __CRT__NO_INLINE
     75   __CRT_INLINE int __cdecl _fstat64i32(int _FileDes,struct _stat64i32 *_Stat)
     76   {
     77     struct _stat64 st;
     78     int ret=_fstat64(_FileDes,&st);
     79     if (ret == -1) {
     80       memset(_Stat,0,sizeof(struct _stat64i32));
     81       return -1;
     82     }
     83     _Stat->st_dev=st.st_dev;
     84     _Stat->st_ino=st.st_ino;
     85     _Stat->st_mode=st.st_mode;
     86     _Stat->st_nlink=st.st_nlink;
     87     _Stat->st_uid=st.st_uid;
     88     _Stat->st_gid=st.st_gid;
     89     _Stat->st_rdev=st.st_rdev;
     90     _Stat->st_size=(_off_t) st.st_size;
     91     _Stat->st_atime=st.st_atime;
     92     _Stat->st_mtime=st.st_mtime;
     93     _Stat->st_ctime=st.st_ctime;
     94     return ret;
     95   }
     96 #endif /* __CRT__NO_INLINE */
     97   _CRTIMP int __cdecl _stat64(const char *_Name,struct _stat64 *_Stat);
     98   _CRTIMP int __cdecl _stat32i64(const char *_Name,struct _stat32i64 *_Stat);
     99   int __cdecl _stat64i32(const char *_Name,struct _stat64i32 *_Stat);
    100 #ifndef __CRT__NO_INLINE
    101   __CRT_INLINE int __cdecl _stat64i32(const char *_Name,struct _stat64i32 *_Stat)
    102   {
    103     struct _stat64 st;
    104     int ret=_stat64(_Name,&st);
    105     if (ret == -1) {
    106       memset(_Stat,0,sizeof(struct _stat64i32));
    107       return -1;
    108     }
    109     _Stat->st_dev=st.st_dev;
    110     _Stat->st_ino=st.st_ino;
    111     _Stat->st_mode=st.st_mode;
    112     _Stat->st_nlink=st.st_nlink;
    113     _Stat->st_uid=st.st_uid;
    114     _Stat->st_gid=st.st_gid;
    115     _Stat->st_rdev=st.st_rdev;
    116     _Stat->st_size=(_off_t) st.st_size;
    117     _Stat->st_atime=st.st_atime;
    118     _Stat->st_mtime=st.st_mtime;
    119     _Stat->st_ctime=st.st_ctime;
    120     return ret;
    121   }
    122 #endif /* __CRT__NO_INLINE */
    123 
    124 #ifndef _WSTAT_DEFINED
    125 #define _WSTAT_DEFINED
    126   _CRTIMP int __cdecl _wstat32(const wchar_t *_Name,struct _stat32 *_Stat);
    127   _CRTIMP int __cdecl _wstat32i64(const wchar_t *_Name,struct _stat32i64 *_Stat);
    128   int __cdecl _wstat64i32(const wchar_t *_Name,struct _stat64i32 *_Stat);
    129   _CRTIMP int __cdecl _wstat64(const wchar_t *_Name,struct _stat64 *_Stat);
    130 #endif
    131 
    132 #ifndef	NO_OLDNAMES
    133 #define	_S_IFBLK	0x3000	/* Block: Is this ever set under w32? */
    134 
    135 #define S_IFMT _S_IFMT
    136 #define S_IFDIR _S_IFDIR
    137 #define S_IFCHR _S_IFCHR
    138 #define S_IFREG _S_IFREG
    139 #define S_IREAD _S_IREAD
    140 #define S_IWRITE _S_IWRITE
    141 #define S_IEXEC _S_IEXEC
    142 #define	S_IFIFO		_S_IFIFO
    143 #define	S_IFBLK		_S_IFBLK
    144 
    145 #define	_S_IRWXU	(_S_IREAD | _S_IWRITE | _S_IEXEC)
    146 #define	_S_IXUSR	_S_IEXEC
    147 #define	_S_IWUSR	_S_IWRITE
    148 
    149 #define	S_IRWXU		_S_IRWXU
    150 #define	S_IXUSR		_S_IXUSR
    151 #define	S_IWUSR		_S_IWUSR
    152 #define	S_IRUSR		_S_IRUSR
    153 #define	_S_IRUSR	_S_IREAD
    154 
    155 #define	S_ISDIR(m)	(((m) & S_IFMT) == S_IFDIR)
    156 #define	S_ISFIFO(m)	(((m) & S_IFMT) == S_IFIFO)
    157 #define	S_ISCHR(m)	(((m) & S_IFMT) == S_IFCHR)
    158 #define	S_ISBLK(m)	(((m) & S_IFMT) == S_IFBLK)
    159 #define	S_ISREG(m)	(((m) & S_IFMT) == S_IFREG)
    160 
    161 #endif
    162 
    163 #if !defined (RC_INVOKED) && !defined (NO_OLDNAMES)
    164 int __cdecl stat(const char *_Filename,struct stat *_Stat);
    165 int __cdecl fstat(int _Desc,struct stat *_Stat);
    166 int __cdecl wstat(const wchar_t *_Filename,struct stat *_Stat);
    167 
    168 #ifndef __CRT__NO_INLINE
    169 #ifdef _USE_32BIT_TIME_T
    170 __CRT_INLINE int __cdecl
    171  fstat(int _Desc,struct stat *_Stat) {
    172   struct _stat32 st;
    173   int ret=_fstat32(_Desc,&st);
    174   if (ret == -1) {
    175     memset(_Stat,0,sizeof(struct stat));
    176     return -1;
    177   }
    178   /* struct stat and struct _stat32
    179      are the same for this case. */
    180   memcpy(_Stat, &st, sizeof(struct _stat32));
    181   return ret;
    182 }
    183 /* Disable it for making sure trailing slash issue is fixed.  */
    184 #if 0
    185 __CRT_INLINE int __cdecl
    186  stat(const char *_Filename,struct stat *_Stat) {
    187   struct _stat32 st;
    188   int ret=_stat32(_Filename,&st);
    189   if (ret == -1) {
    190     memset(_Stat,0,sizeof(struct stat));
    191     return -1;
    192   }
    193   /* struct stat and struct _stat32
    194      are the same for this case. */
    195   memcpy(_Stat, &st, sizeof(struct _stat32));
    196   return ret;
    197 }
    198 #endif
    199 #else
    200 __CRT_INLINE int __cdecl
    201  fstat(int _Desc,struct stat *_Stat) {
    202   struct _stat64 st;
    203   int ret=_fstat64(_Desc,&st);
    204   if (ret == -1) {
    205     memset(_Stat,0,sizeof(struct stat));
    206     return -1;
    207   }
    208   /* struct stat and struct _stat64i32
    209      are the same for this case. */
    210   _Stat->st_dev=st.st_dev;
    211   _Stat->st_ino=st.st_ino;
    212   _Stat->st_mode=st.st_mode;
    213   _Stat->st_nlink=st.st_nlink;
    214   _Stat->st_uid=st.st_uid;
    215   _Stat->st_gid=st.st_gid;
    216   _Stat->st_rdev=st.st_rdev;
    217   _Stat->st_size=(_off_t) st.st_size;
    218   _Stat->st_atime=st.st_atime;
    219   _Stat->st_mtime=st.st_mtime;
    220   _Stat->st_ctime=st.st_ctime;
    221   return ret;
    222 }
    223 /* Disable it for making sure trailing slash issue is fixed.  */
    224 #if 0
    225 __CRT_INLINE int __cdecl
    226  stat(const char *_Filename,struct stat *_Stat) {
    227   struct _stat64 st;
    228   int ret=_stat64(_Filename,&st);
    229   if (ret == -1) {
    230     memset(_Stat,0,sizeof(struct stat));
    231     return -1;
    232   }
    233   /* struct stat and struct _stat64i32
    234      are the same for this case. */
    235   _Stat->st_dev=st.st_dev;
    236   _Stat->st_ino=st.st_ino;
    237   _Stat->st_mode=st.st_mode;
    238   _Stat->st_nlink=st.st_nlink;
    239   _Stat->st_uid=st.st_uid;
    240   _Stat->st_gid=st.st_gid;
    241   _Stat->st_rdev=st.st_rdev;
    242   _Stat->st_size=(_off_t) st.st_size;
    243   _Stat->st_atime=st.st_atime;
    244   _Stat->st_mtime=st.st_mtime;
    245   _Stat->st_ctime=st.st_ctime;
    246   return ret;
    247 }
    248 #endif
    249 #endif /* _USE_32BIT_TIME_T */
    250 #endif /* __CRT__NO_INLINE */
    251 #endif /* !RC_INVOKED && !NO_OLDNAMES */
    252 
    253 #if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
    254 #ifdef _USE_32BIT_TIME_T
    255 #define stat _stat32i64
    256 #define fstat _fstat32i64
    257 #else
    258 #define stat _stat64
    259 #define fstat _fstat64
    260 #endif
    261 #endif
    262 
    263 #ifdef __cplusplus
    264 }
    265 #endif
    266 
    267 #pragma pack(pop)
    268 
    269 #endif /* _INC_STAT */
    270 
    271