io.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * io.h
  3. *
  4. * System level I/O functions and types.
  5. *
  6. * This file is part of the Mingw32 package.
  7. *
  8. * Contributors:
  9. * Created by Colin Peters <[email protected]>
  10. *
  11. * THIS SOFTWARE IS NOT COPYRIGHTED
  12. *
  13. * This source code is offered for use in the public domain. You may
  14. * use, modify or distribute it freely.
  15. *
  16. * This code is distributed in the hope that it will be useful but
  17. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  18. * DISCLAIMED. This includes but is not limited to warranties of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. * $Revision: 1.2 $
  22. * $Author: bellard $
  23. * $Date: 2005/04/17 13:14:29 $
  24. *
  25. */
  26. #ifndef __STRICT_ANSI__
  27. #ifndef _IO_H_
  28. #define _IO_H_
  29. /* All the headers include this file. */
  30. #include <_mingw.h>
  31. /* We need the definition of FILE anyway... */
  32. #include <stdio.h>
  33. /* MSVC's io.h contains the stuff from dir.h, so I will too.
  34. * NOTE: This also defines off_t, the file offset type, through
  35. * an inclusion of sys/types.h */
  36. #ifndef __STRICT_ANSI__
  37. #include <sys/types.h> /* To get time_t. */
  38. /*
  39. * Attributes of files as returned by _findfirst et al.
  40. */
  41. #define _A_NORMAL 0x00000000
  42. #define _A_RDONLY 0x00000001
  43. #define _A_HIDDEN 0x00000002
  44. #define _A_SYSTEM 0x00000004
  45. #define _A_VOLID 0x00000008
  46. #define _A_SUBDIR 0x00000010
  47. #define _A_ARCH 0x00000020
  48. #ifndef RC_INVOKED
  49. #ifndef _FSIZE_T_DEFINED
  50. typedef unsigned long _fsize_t;
  51. #define _FSIZE_T_DEFINED
  52. #endif
  53. /*
  54. * The following structure is filled in by _findfirst or _findnext when
  55. * they succeed in finding a match.
  56. */
  57. struct _finddata_t
  58. {
  59. unsigned attrib; /* Attributes, see constants above. */
  60. time_t time_create;
  61. time_t time_access; /* always midnight local time */
  62. time_t time_write;
  63. _fsize_t size;
  64. char name[FILENAME_MAX]; /* may include spaces. */
  65. };
  66. struct _finddatai64_t {
  67. unsigned attrib;
  68. time_t time_create;
  69. time_t time_access;
  70. time_t time_write;
  71. __int64 size;
  72. char name[FILENAME_MAX];
  73. };
  74. #ifndef _WFINDDATA_T_DEFINED
  75. struct _wfinddata_t {
  76. unsigned attrib;
  77. time_t time_create; /* -1 for FAT file systems */
  78. time_t time_access; /* -1 for FAT file systems */
  79. time_t time_write;
  80. _fsize_t size;
  81. wchar_t name[FILENAME_MAX]; /* may include spaces. */
  82. };
  83. struct _wfinddatai64_t {
  84. unsigned attrib;
  85. time_t time_create;
  86. time_t time_access;
  87. time_t time_write;
  88. __int64 size;
  89. wchar_t name[FILENAME_MAX];
  90. };
  91. #define _WFINDDATA_T_DEFINED
  92. #endif
  93. #ifdef __cplusplus
  94. extern "C" {
  95. #endif
  96. /*
  97. * Functions for searching for files. _findfirst returns -1 if no match
  98. * is found. Otherwise it returns a handle to be used in _findnext and
  99. * _findclose calls. _findnext also returns -1 if no match could be found,
  100. * and 0 if a match was found. Call _findclose when you are finished.
  101. */
  102. int _findfirst (const char*, struct _finddata_t*);
  103. int _findnext (int, struct _finddata_t*);
  104. int _findclose (int);
  105. int _chdir (const char*);
  106. char* _getcwd (char*, int);
  107. int _mkdir (const char*);
  108. char* _mktemp (char*);
  109. int _rmdir (const char*);
  110. #ifdef __MSVCRT__
  111. __int64 _filelengthi64(int);
  112. long _findfirsti64(const char*, struct _finddatai64_t*);
  113. int _findnexti64(long, struct _finddatai64_t*);
  114. __int64 _lseeki64(int, __int64, int);
  115. __int64 _telli64(int);
  116. #endif /* __MSVCRT__ */
  117. #ifndef _NO_OLDNAMES
  118. #ifndef _UWIN
  119. int chdir (const char*);
  120. char* getcwd (char*, int);
  121. int mkdir (const char*);
  122. char* mktemp (char*);
  123. int rmdir (const char*);
  124. #endif /* _UWIN */
  125. #endif /* Not _NO_OLDNAMES */
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif /* Not RC_INVOKED */
  130. #endif /* Not __STRICT_ANSI__ */
  131. /* TODO: Maximum number of open handles has not been tested, I just set
  132. * it the same as FOPEN_MAX. */
  133. #define HANDLE_MAX FOPEN_MAX
  134. /* Some defines for _access nAccessMode (MS doesn't define them, but
  135. * it doesn't seem to hurt to add them). */
  136. #define F_OK 0 /* Check for file existence */
  137. #define X_OK 1 /* Check for execute permission. */
  138. #define W_OK 2 /* Check for write permission */
  139. #define R_OK 4 /* Check for read permission */
  140. #ifndef RC_INVOKED
  141. #ifdef __cplusplus
  142. extern "C" {
  143. #endif
  144. int _access (const char*, int);
  145. int _chsize (int, long);
  146. int _close (int);
  147. int _commit(int);
  148. /* NOTE: The only significant bit in unPermissions appears to be bit 7 (0x80),
  149. * the "owner write permission" bit (on FAT). */
  150. int _creat (const char*, unsigned);
  151. int _dup (int);
  152. int _dup2 (int, int);
  153. long _filelength (int);
  154. int _fileno (FILE*);
  155. long _get_osfhandle (int);
  156. int _isatty (int);
  157. /* In a very odd turn of events this function is excluded from those
  158. * files which define _STREAM_COMPAT. This is required in order to
  159. * build GNU libio because of a conflict with _eof in streambuf.h
  160. * line 107. Actually I might just be able to change the name of
  161. * the enum member in streambuf.h... we'll see. TODO */
  162. #ifndef _STREAM_COMPAT
  163. int _eof (int);
  164. #endif
  165. /* LK_... locking commands defined in sys/locking.h. */
  166. int _locking (int, int, long);
  167. long _lseek (int, long, int);
  168. /* Optional third argument is unsigned unPermissions. */
  169. int _open (const char*, int, ...);
  170. int _open_osfhandle (long, int);
  171. int _pipe (int *, unsigned int, int);
  172. int _read (int, void*, unsigned int);
  173. /* SH_... flags for nShFlags defined in share.h
  174. * Optional fourth argument is unsigned unPermissions */
  175. int _sopen (const char*, int, int, ...);
  176. long _tell (int);
  177. /* Should umask be in sys/stat.h and/or sys/types.h instead? */
  178. int _umask (int);
  179. int _unlink (const char*);
  180. int _write (int, const void*, unsigned int);
  181. /* Wide character versions. Also declared in wchar.h. */
  182. /* Not in crtdll.dll */
  183. #if !defined (_WIO_DEFINED)
  184. #if defined (__MSVCRT__)
  185. int _waccess(const wchar_t*, int);
  186. int _wchmod(const wchar_t*, int);
  187. int _wcreat(const wchar_t*, int);
  188. long _wfindfirst(wchar_t*, struct _wfinddata_t*);
  189. int _wfindnext(long, struct _wfinddata_t *);
  190. int _wunlink(const wchar_t*);
  191. int _wopen(const wchar_t*, int, ...);
  192. int _wsopen(const wchar_t*, int, int, ...);
  193. wchar_t * _wmktemp(wchar_t*);
  194. long _wfindfirsti64(const wchar_t*, struct _wfinddatai64_t*);
  195. int _wfindnexti64(long, struct _wfinddatai64_t*);
  196. #endif /* defined (__MSVCRT__) */
  197. #define _WIO_DEFINED
  198. #endif /* _WIO_DEFINED */
  199. #ifndef _NO_OLDNAMES
  200. /*
  201. * Non-underscored versions of non-ANSI functions to improve portability.
  202. * These functions live in libmoldname.a.
  203. */
  204. #ifndef _UWIN
  205. int access (const char*, int);
  206. int chsize (int, long );
  207. int close (int);
  208. int creat (const char*, int);
  209. int dup (int);
  210. int dup2 (int, int);
  211. int eof (int);
  212. long filelength (int);
  213. int fileno (FILE*);
  214. int isatty (int);
  215. long lseek (int, long, int);
  216. int open (const char*, int, ...);
  217. int read (int, void*, unsigned int);
  218. int sopen (const char*, int, int, ...);
  219. long tell (int);
  220. int umask (int);
  221. int unlink (const char*);
  222. int write (int, const void*, unsigned int);
  223. #endif /* _UWIN */
  224. /* Wide character versions. Also declared in wchar.h. */
  225. /* Where do these live? Not in libmoldname.a nor in libmsvcrt.a */
  226. #if 0
  227. int waccess(const wchar_t *, int);
  228. int wchmod(const wchar_t *, int);
  229. int wcreat(const wchar_t *, int);
  230. long wfindfirst(wchar_t *, struct _wfinddata_t *);
  231. int wfindnext(long, struct _wfinddata_t *);
  232. int wunlink(const wchar_t *);
  233. int wrename(const wchar_t *, const wchar_t *);
  234. int wopen(const wchar_t *, int, ...);
  235. int wsopen(const wchar_t *, int, int, ...);
  236. wchar_t * wmktemp(wchar_t *);
  237. #endif
  238. #endif /* Not _NO_OLDNAMES */
  239. #ifdef __cplusplus
  240. }
  241. #endif
  242. #endif /* Not RC_INVOKED */
  243. #endif /* _IO_H_ not defined */
  244. #endif /* Not strict ANSI */