Home | History | Annotate | Download | only in include
      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 _IO_H_
      7 #define _IO_H_
      8 
      9 #include <crtdefs.h>
     10 #include <string.h>
     11 
     12 #pragma pack(push,_CRT_PACKING)
     13 
     14 #ifdef __cplusplus
     15 extern "C" {
     16 #endif
     17 
     18 _CRTIMP char* __cdecl _getcwd (char*, int);
     19 #ifndef _FSIZE_T_DEFINED
     20   typedef unsigned long _fsize_t;
     21 #define _FSIZE_T_DEFINED
     22 #endif
     23 
     24 #ifndef _FINDDATA_T_DEFINED
     25 
     26   struct _finddata32_t {
     27     unsigned attrib;
     28     __time32_t time_create;
     29     __time32_t time_access;
     30     __time32_t time_write;
     31     _fsize_t size;
     32     char name[260];
     33   };
     34 
     35   struct _finddata32i64_t {
     36     unsigned attrib;
     37     __time32_t time_create;
     38     __time32_t time_access;
     39     __time32_t time_write;
     40     __MINGW_EXTENSION __int64 size;
     41     char name[260];
     42   };
     43 
     44   struct _finddata64i32_t {
     45     unsigned attrib;
     46     __time64_t time_create;
     47     __time64_t time_access;
     48     __time64_t time_write;
     49     _fsize_t size;
     50     char name[260];
     51   };
     52 
     53   struct __finddata64_t {
     54     unsigned attrib;
     55     __time64_t time_create;
     56     __time64_t time_access;
     57     __time64_t time_write;
     58     __MINGW_EXTENSION __int64 size;
     59     char name[260];
     60   };
     61 
     62 #ifdef _USE_32BIT_TIME_T
     63 #define _finddata_t _finddata32_t
     64 #define _finddatai64_t _finddata32i64_t
     65 
     66 #define _findfirst32 _findfirst
     67 #define _findnext32 _findnext
     68 #define _findfirsti64 _findfirst32i64
     69 #define _findnexti64 _findnext32i64
     70 #else
     71 #define _finddata_t _finddata64i32_t
     72 #define _finddatai64_t __finddata64_t
     73 
     74 #define _findfirst _findfirst64i32
     75 #define _findnext _findnext64i32
     76 #define _findfirsti64 _findfirst64
     77 #define _findnexti64 _findnext64
     78 #endif /* _USE_32BIT_TIME_T */
     79 
     80 #define _FINDDATA_T_DEFINED
     81 #endif /* _FINDDATA_T_DEFINED */
     82 
     83 #ifndef _WFINDDATA_T_DEFINED
     84 
     85   struct _wfinddata32_t {
     86     unsigned attrib;
     87     __time32_t time_create;
     88     __time32_t time_access;
     89     __time32_t time_write;
     90     _fsize_t size;
     91     wchar_t name[260];
     92   };
     93 
     94   struct _wfinddata32i64_t {
     95     unsigned attrib;
     96     __time32_t time_create;
     97     __time32_t time_access;
     98     __time32_t time_write;
     99     __MINGW_EXTENSION __int64 size;
    100     wchar_t name[260];
    101   };
    102 
    103   struct _wfinddata64i32_t {
    104     unsigned attrib;
    105     __time64_t time_create;
    106     __time64_t time_access;
    107     __time64_t time_write;
    108     _fsize_t size;
    109     wchar_t name[260];
    110   };
    111 
    112   struct _wfinddata64_t {
    113     unsigned attrib;
    114     __time64_t time_create;
    115     __time64_t time_access;
    116     __time64_t time_write;
    117     __MINGW_EXTENSION __int64 size;
    118     wchar_t name[260];
    119   };
    120 
    121 #ifdef _USE_32BIT_TIME_T
    122 #define _wfinddata_t _wfinddata32_t
    123 #define _wfinddatai64_t _wfinddata32i64_t
    124 
    125 #define _wfindfirst32 _wfindfirst
    126 #define _wfindnext32 _wfindnext
    127 #define _wfindfirst32i64 _wfindfirsti64
    128 #define _wfindnext32i64 _wfindnexti64
    129 #else
    130 #define _wfinddata_t _wfinddata64i32_t
    131 #define _wfinddatai64_t _wfinddata64_t
    132 
    133 #define _wfindfirst _wfindfirst64i32
    134 #define _wfindnext _wfindnext64i32
    135 #define _wfindfirsti64 _wfindfirst64
    136 #define _wfindnexti64 _wfindnext64
    137 #endif /* _USE_32BIT_TIME_T */
    138 
    139 #define _WFINDDATA_T_DEFINED
    140 #endif /* _WFINDDATA_T_DEFINED */
    141 
    142 #define _A_NORMAL 0x00
    143 #define _A_RDONLY 0x01
    144 #define _A_HIDDEN 0x02
    145 #define _A_SYSTEM 0x04
    146 #define _A_SUBDIR 0x10
    147 #define _A_ARCH 0x20
    148 
    149 #ifndef _SIZE_T_DEFINED
    150 #define _SIZE_T_DEFINED
    151 #undef size_t
    152 #ifdef _WIN64
    153   __MINGW_EXTENSION typedef unsigned __int64 size_t;
    154 #else
    155   typedef unsigned int size_t;
    156 #endif /* _WIN64 */
    157 #endif /* _SIZE_T_DEFINED */
    158 
    159 #ifndef _SSIZE_T_DEFINED
    160 #define _SSIZE_T_DEFINED
    161 #undef ssize_t
    162 #ifdef _WIN64
    163   __MINGW_EXTENSION typedef __int64 ssize_t;
    164 #else
    165   typedef int ssize_t;
    166 #endif /* _WIN64 */
    167 #endif /* _SSIZE_T_DEFINED */
    168 
    169 #include <_mingw_off_t.h>
    170 
    171   /* Some defines for _access nAccessMode (MS doesn't define them, but
    172   * it doesn't seem to hurt to add them). */
    173 #define	F_OK	0	/* Check for file existence */
    174 #define	X_OK	1	/* Check for execute permission. */
    175 #define	W_OK	2	/* Check for write permission */
    176 #define	R_OK	4	/* Check for read permission */
    177 
    178   _CRTIMP int __cdecl _access(const char *_Filename,int _AccessMode);
    179   _CRTIMP errno_t __cdecl _access_s(const char *_Filename,int _AccessMode);
    180   _CRTIMP int __cdecl _chmod(const char *_Filename,int _Mode);
    181   _CRTIMP int __cdecl _chsize(int _FileHandle,long _Size) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    182   _CRTIMP errno_t __cdecl _chsize_s (int _FileHandle,__int64 _Size);
    183   _CRTIMP int __cdecl _close(int _FileHandle);
    184   _CRTIMP int __cdecl _commit(int _FileHandle);
    185   _CRTIMP int __cdecl _creat(const char *_Filename,int _PermissionMode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    186   _CRTIMP int __cdecl _dup(int _FileHandle);
    187   _CRTIMP int __cdecl _dup2(int _FileHandleSrc,int _FileHandleDst);
    188   _CRTIMP int __cdecl _eof(int _FileHandle);
    189   _CRTIMP long __cdecl _filelength(int _FileHandle);
    190   _CRTIMP intptr_t __cdecl _findfirst32(const char *_Filename,struct _finddata32_t *_FindData);
    191   _CRTIMP int __cdecl _findnext32(intptr_t _FindHandle,struct _finddata32_t *_FindData);
    192   _CRTIMP int __cdecl _findclose(intptr_t _FindHandle);
    193   _CRTIMP int __cdecl _isatty(int _FileHandle);
    194   _CRTIMP int __cdecl _locking(int _FileHandle,int _LockMode,long _NumOfBytes);
    195   _CRTIMP long __cdecl _lseek(int _FileHandle,long _Offset,int _Origin);
    196   _off64_t lseek64(int fd,_off64_t offset, int whence);
    197   _CRTIMP char *__cdecl _mktemp(char *_TemplateName) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    198   _CRTIMP errno_t __cdecl _mktemp_s (char *_TemplateName,size_t _Size);
    199   _CRTIMP int __cdecl _pipe(int *_PtHandles,unsigned int _PipeSize,int _TextMode);
    200   _CRTIMP int __cdecl _read(int _FileHandle,void *_DstBuf,unsigned int _MaxCharCount);
    201 
    202 #ifndef _CRT_DIRECTORY_DEFINED
    203 #define _CRT_DIRECTORY_DEFINED
    204   int __cdecl remove(const char *_Filename);
    205   int __cdecl rename(const char *_OldFilename,const char *_NewFilename);
    206   _CRTIMP int __cdecl _unlink(const char *_Filename);
    207 #ifndef	NO_OLDNAMES
    208   int __cdecl unlink(const char *_Filename) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    209 #endif
    210 #endif
    211 
    212   _CRTIMP int __cdecl _setmode(int _FileHandle,int _Mode);
    213   _CRTIMP long __cdecl _tell(int _FileHandle);
    214   _CRTIMP int __cdecl _umask(int _Mode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    215   _CRTIMP errno_t __cdecl _umask_s (int _NewMode,int *_OldMode);
    216   _CRTIMP int __cdecl _write(int _FileHandle,const void *_Buf,unsigned int _MaxCharCount);
    217 
    218   __MINGW_EXTENSION _CRTIMP __int64 __cdecl _filelengthi64(int _FileHandle);
    219   _CRTIMP intptr_t __cdecl _findfirst32i64(const char *_Filename,struct _finddata32i64_t *_FindData);
    220   _CRTIMP intptr_t __cdecl _findfirst64(const char *_Filename,struct __finddata64_t *_FindData);
    221 #ifdef __cplusplus
    222 #include <string.h>
    223 #endif
    224   intptr_t __cdecl _findfirst64i32(const char *_Filename,struct _finddata64i32_t *_FindData);
    225 #ifndef __CRT__NO_INLINE
    226   __CRT_INLINE intptr_t __cdecl _findfirst64i32(const char *_Filename,struct _finddata64i32_t *_FindData)
    227   {
    228     struct __finddata64_t fd;
    229     intptr_t ret = _findfirst64(_Filename,&fd);
    230     if (ret == -1) {
    231       memset(_FindData,0,sizeof(struct _finddata64i32_t));
    232       return -1;
    233     }
    234     _FindData->attrib=fd.attrib;
    235     _FindData->time_create=fd.time_create;
    236     _FindData->time_access=fd.time_access;
    237     _FindData->time_write=fd.time_write;
    238     _FindData->size=(_fsize_t) fd.size;
    239     strncpy(_FindData->name,fd.name,260);
    240     return ret;
    241   }
    242 #endif /* __CRT__NO_INLINE */
    243   _CRTIMP int __cdecl _findnext32i64(intptr_t _FindHandle,struct _finddata32i64_t *_FindData);
    244   _CRTIMP int __cdecl _findnext64(intptr_t _FindHandle,struct __finddata64_t *_FindData);
    245   int __cdecl _findnext64i32(intptr_t _FindHandle,struct _finddata64i32_t *_FindData);
    246 #ifndef __CRT__NO_INLINE
    247   __CRT_INLINE int __cdecl _findnext64i32(intptr_t _FindHandle,struct _finddata64i32_t *_FindData)
    248   {
    249     struct __finddata64_t fd;
    250     int ret = _findnext64(_FindHandle,&fd);
    251     if (ret == -1) {
    252       memset(_FindData,0,sizeof(struct _finddata64i32_t));
    253       return -1;
    254     }
    255     _FindData->attrib=fd.attrib;
    256     _FindData->time_create=fd.time_create;
    257     _FindData->time_access=fd.time_access;
    258     _FindData->time_write=fd.time_write;
    259     _FindData->size=(_fsize_t) fd.size;
    260     strncpy(_FindData->name,fd.name,260);
    261     return ret;
    262   }
    263 #endif /* __CRT__NO_INLINE */
    264   __MINGW_EXTENSION __int64 __cdecl _lseeki64(int _FileHandle,__int64 _Offset,int _Origin);
    265   __MINGW_EXTENSION __int64 __cdecl _telli64(int _FileHandle);
    266 
    267 #ifndef NO_OLDNAMES
    268 #ifndef _UWIN
    269   int __cdecl chdir (const char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    270   char *__cdecl getcwd (char *, int) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    271   int __cdecl mkdir (const char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    272   char *__cdecl mktemp(char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    273   int __cdecl rmdir (const char*) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    274   int __cdecl chmod (const char *, int) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    275 #endif /* _UWIN */
    276 #endif /* Not NO_OLDNAMES */
    277 
    278   _CRTIMP errno_t __cdecl _sopen_s(int *_FileHandle,const char *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionMode);
    279 
    280   _CRTIMP int __cdecl _open(const char *_Filename,int _OpenFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    281   _CRTIMP int __cdecl _sopen(const char *_Filename,int _OpenFlag,int _ShareFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    282 
    283 #ifndef _WIO_DEFINED
    284 #define _WIO_DEFINED
    285   _CRTIMP int __cdecl _waccess(const wchar_t *_Filename,int _AccessMode);
    286   _CRTIMP errno_t __cdecl _waccess_s (const wchar_t *_Filename,int _AccessMode);
    287   _CRTIMP int __cdecl _wchmod(const wchar_t *_Filename,int _Mode);
    288   _CRTIMP int __cdecl _wcreat(const wchar_t *_Filename,int _PermissionMode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    289   _CRTIMP intptr_t __cdecl _wfindfirst32(const wchar_t *_Filename,struct _wfinddata32_t *_FindData);
    290   _CRTIMP int __cdecl _wfindnext32(intptr_t _FindHandle,struct _wfinddata32_t *_FindData);
    291   _CRTIMP int __cdecl _wunlink(const wchar_t *_Filename);
    292   _CRTIMP int __cdecl _wrename(const wchar_t *_OldFilename,const wchar_t *_NewFilename);
    293   _CRTIMP wchar_t *__cdecl _wmktemp(wchar_t *_TemplateName) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    294   _CRTIMP errno_t __cdecl _wmktemp_s (wchar_t *_TemplateName, size_t _SizeInWords);
    295 
    296   _CRTIMP intptr_t __cdecl _wfindfirst32i64(const wchar_t *_Filename,struct _wfinddata32i64_t *_FindData);
    297   intptr_t __cdecl _wfindfirst64i32(const wchar_t *_Filename,struct _wfinddata64i32_t *_FindData);
    298   _CRTIMP intptr_t __cdecl _wfindfirst64(const wchar_t *_Filename,struct _wfinddata64_t *_FindData);
    299   _CRTIMP int __cdecl _wfindnext32i64(intptr_t _FindHandle,struct _wfinddata32i64_t *_FindData);
    300   int __cdecl _wfindnext64i32(intptr_t _FindHandle,struct _wfinddata64i32_t *_FindData);
    301   _CRTIMP int __cdecl _wfindnext64(intptr_t _FindHandle,struct _wfinddata64_t *_FindData);
    302 
    303   _CRTIMP errno_t __cdecl _wsopen_s(int *_FileHandle,const wchar_t *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionFlag);
    304 
    305   _CRTIMP int __cdecl _wopen(const wchar_t *_Filename,int _OpenFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    306   _CRTIMP int __cdecl _wsopen(const wchar_t *_Filename,int _OpenFlag,int _ShareFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    307 
    308 #endif
    309 
    310   int __cdecl __lock_fhandle(int _Filehandle);
    311   void __cdecl _unlock_fhandle(int _Filehandle);
    312   _CRTIMP intptr_t __cdecl _get_osfhandle(int _FileHandle);
    313   _CRTIMP int __cdecl _open_osfhandle(intptr_t _OSFileHandle,int _Flags);
    314 
    315 #ifndef NO_OLDNAMES
    316   int __cdecl access(const char *_Filename,int _AccessMode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    317   int __cdecl chmod(const char *_Filename,int _AccessMode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    318   int __cdecl chsize(int _FileHandle,long _Size) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    319   int __cdecl close(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    320   int __cdecl creat(const char *_Filename,int _PermissionMode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    321   int __cdecl dup(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    322   int __cdecl dup2(int _FileHandleSrc,int _FileHandleDst) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    323   int __cdecl eof(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    324   long __cdecl filelength(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    325   int __cdecl isatty(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    326   int __cdecl locking(int _FileHandle,int _LockMode,long _NumOfBytes) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    327   long __cdecl lseek(int _FileHandle,long _Offset,int _Origin) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    328   char *__cdecl mktemp(char *_TemplateName)  __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    329   int __cdecl open(const char *_Filename,int _OpenFlag,...)  __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    330   int __cdecl read(int _FileHandle,void *_DstBuf,unsigned int _MaxCharCount)  __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    331   int __cdecl setmode(int _FileHandle,int _Mode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    332   int __cdecl sopen(const char *_Filename,int _OpenFlag,int _ShareFlag,...) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    333   long __cdecl tell(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    334   int __cdecl umask(int _Mode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    335   int __cdecl write(int _Filehandle,const void *_Buf,unsigned int _MaxCharCount) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    336 #endif
    337 
    338 #ifndef _FILE_OFFSET_BITS_SET_LSEEK
    339 #define _FILE_OFFSET_BITS_SET_LSEEK
    340 #if (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64))
    341 #define lseek lseek64
    342 #endif /* (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)) */
    343 #endif /* _FILE_OFFSET_BITS_SET_LSEEK */
    344 
    345 #ifdef _POSIX
    346 
    347 /* Misc stuff */
    348 char *getlogin(void);
    349 #ifdef __USE_MINGW_ALARM
    350 unsigned int alarm(unsigned int seconds);
    351 #endif
    352 
    353 #endif
    354 
    355 #ifdef __USE_MINGW_ACCESS
    356 /*  Old versions of MSVCRT access() just ignored X_OK, while the version
    357     shipped with Vista, returns an error code.  This will restore the
    358     old behaviour  */
    359 static inline int __mingw_access (const char *__fname, int __mode) {
    360   return  _access (__fname, __mode & ~X_OK);
    361 }
    362 
    363 #define access(__f,__m)  __mingw_access (__f, __m)
    364 #endif
    365 
    366 
    367 #ifdef __cplusplus
    368 }
    369 #endif
    370 
    371 
    372 #pragma pack(pop)
    373 
    374 #endif /* End _IO_H_ */
    375 
    376