home *** CD-ROM | disk | FTP | other *** search
/ Beginning C++ Through Gam…rogramming (2nd Edition) / BCGP2E.ISO / bloodshed / devcpp-4.9.9.2_setup.exe / io.h < prev    next >
C/C++ Source or Header  |  2005-01-29  |  10KB  |  314 lines

  1. /* 
  2.  * io.h
  3.  * This file has no copyright assigned and is placed in the Public Domain.
  4.  * This file is a part of the mingw-runtime package.
  5.  * No warranty is given; refer to the file DISCLAIMER within the package.
  6.  *
  7.  * System level I/O functions and types.
  8.  *
  9.  */
  10. #ifndef    _IO_H_
  11. #define    _IO_H_
  12.  
  13. /* All the headers include this file. */
  14. #include <_mingw.h>
  15.  
  16. /* MSVC's io.h contains the stuff from dir.h, so I will too.
  17.  * NOTE: This also defines off_t, the file offset type, through
  18.  *       an inclusion of sys/types.h */
  19.  
  20. #include <sys/types.h>    /* To get time_t.  */
  21. #include <stdint.h>  /* For intptr_t.  */
  22.  
  23. /*
  24.  * Attributes of files as returned by _findfirst et al.
  25.  */
  26. #define    _A_NORMAL    0x00000000
  27. #define    _A_RDONLY    0x00000001
  28. #define    _A_HIDDEN    0x00000002
  29. #define    _A_SYSTEM    0x00000004
  30. #define    _A_VOLID    0x00000008
  31. #define    _A_SUBDIR    0x00000010
  32. #define    _A_ARCH        0x00000020
  33.  
  34.  
  35. #ifndef RC_INVOKED
  36.  
  37. #ifndef    _FSIZE_T_DEFINED
  38. typedef    unsigned long    _fsize_t;
  39. #define _FSIZE_T_DEFINED
  40. #endif
  41.  
  42. /*
  43.  * The maximum length of a file name. You should use GetVolumeInformation
  44.  * instead of this constant. But hey, this works.
  45.  * Also defined in stdio.h. 
  46.  */
  47. #ifndef FILENAME_MAX
  48. #define    FILENAME_MAX    (260)
  49. #endif
  50.  
  51. /*
  52.  * The following structure is filled in by _findfirst or _findnext when
  53.  * they succeed in finding a match.
  54.  */
  55. struct _finddata_t
  56. {
  57.     unsigned    attrib;        /* Attributes, see constants above. */
  58.     time_t        time_create;
  59.     time_t        time_access;    /* always midnight local time */
  60.     time_t        time_write;
  61.     _fsize_t    size;
  62.     char        name[FILENAME_MAX];    /* may include spaces. */
  63. };
  64.  
  65. struct _finddatai64_t {
  66.     unsigned    attrib;
  67.     time_t      time_create;
  68.     time_t      time_access;
  69.     time_t      time_write;
  70.     __int64     size;
  71.     char        name[FILENAME_MAX];
  72. };
  73.  
  74. struct __finddata64_t {
  75.         unsigned    attrib;
  76.         __time64_t  time_create;    
  77.         __time64_t  time_access;    
  78.         __time64_t  time_write;
  79.         _fsize_t    size;
  80.          char       name[FILENAME_MAX];
  81. };
  82.  
  83. #ifndef _WFINDDATA_T_DEFINED
  84. struct _wfinddata_t {
  85.         unsigned    attrib;
  86.         time_t        time_create;    /* -1 for FAT file systems */
  87.         time_t        time_access;    /* -1 for FAT file systems */
  88.         time_t        time_write;
  89.         _fsize_t    size;
  90.         wchar_t        name[FILENAME_MAX];    /* may include spaces. */
  91. };
  92.  
  93. struct _wfinddatai64_t {
  94.     unsigned    attrib;
  95.     time_t      time_create;
  96.     time_t      time_access;
  97.     time_t      time_write;
  98.     __int64     size;
  99.     wchar_t     name[FILENAME_MAX];
  100. };
  101.  
  102. struct __wfinddata64_t {
  103.         unsigned    attrib;
  104.         __time64_t  time_create;    
  105.         __time64_t  time_access;
  106.         __time64_t  time_write;
  107.         _fsize_t    size;
  108.         wchar_t     name[FILENAME_MAX];
  109. };
  110.  
  111. #define _WFINDDATA_T_DEFINED
  112. #endif
  113.  
  114. #ifdef    __cplusplus
  115. extern "C" {
  116. #endif
  117.  
  118. /*
  119.  * Functions for searching for files. _findfirst returns -1 if no match
  120.  * is found. Otherwise it returns a handle to be used in _findnext and
  121.  * _findclose calls. _findnext also returns -1 if no match could be found,
  122.  * and 0 if a match was found. Call _findclose when you are finished.
  123.  */
  124. /*  FIXME: Should these all use intptr_t, as per recent MSDN docs?  */
  125. _CRTIMP long __cdecl _findfirst (const char*, struct _finddata_t*);
  126. _CRTIMP int __cdecl _findnext (long, struct _finddata_t*);
  127. _CRTIMP int __cdecl _findclose (long);
  128.  
  129. _CRTIMP int __cdecl _chdir (const char*);
  130. _CRTIMP char* __cdecl _getcwd (char*, int);
  131. _CRTIMP int __cdecl _mkdir (const char*);
  132. _CRTIMP char* __cdecl _mktemp (char*);
  133. _CRTIMP int __cdecl _rmdir (const char*);
  134. _CRTIMP int __cdecl _chmod (const char*, int);
  135.  
  136. #ifdef __MSVCRT__
  137. _CRTIMP __int64 __cdecl _filelengthi64(int);
  138. _CRTIMP long __cdecl _findfirsti64(const char*, struct _finddatai64_t*);
  139. _CRTIMP int __cdecl _findnexti64(long, struct _finddatai64_t*);
  140. _CRTIMP __int64 __cdecl _lseeki64(int, __int64, int);
  141. _CRTIMP __int64 __cdecl _telli64(int);
  142. /* These require newer versions of msvcrt.dll (6.1 or higher). */ 
  143. #if __MSVCRT_VERSION__ >= 0x0601
  144. _CRTIMP intptr_t __cdecl _findfirst64(const char*, struct __finddata64_t*);
  145. _CRTIMP intptr_t __cdecl _findnext64(intptr_t, struct __finddata64_t*); 
  146. #endif /* __MSVCRT_VERSION__ >= 0x0601 */
  147.  
  148. #ifndef __NO_MINGW_LFS
  149. __CRT_INLINE off64_t lseek64 (int fd, off64_t offset, int whence) 
  150. {
  151.   return _lseeki64(fd, (__int64) offset, whence);
  152. }
  153. #endif
  154.  
  155. #endif /* __MSVCRT__ */
  156.  
  157. #ifndef _NO_OLDNAMES
  158.  
  159. #ifndef _UWIN
  160. _CRTIMP int __cdecl chdir (const char*);
  161. _CRTIMP char* __cdecl getcwd (char*, int);
  162. _CRTIMP int __cdecl mkdir (const char*);
  163. _CRTIMP char* __cdecl mktemp (char*);
  164. _CRTIMP int __cdecl rmdir (const char*);
  165. _CRTIMP int __cdecl chmod (const char*, int);
  166. #endif /* _UWIN */
  167.  
  168. #endif /* Not _NO_OLDNAMES */
  169.  
  170. #ifdef    __cplusplus
  171. }
  172. #endif
  173.  
  174. #endif    /* Not RC_INVOKED */
  175.  
  176. /* TODO: Maximum number of open handles has not been tested, I just set
  177.  * it the same as FOPEN_MAX. */
  178. #define    HANDLE_MAX    FOPEN_MAX
  179.  
  180. /* Some defines for _access nAccessMode (MS doesn't define them, but
  181.  * it doesn't seem to hurt to add them). */
  182. #define    F_OK    0    /* Check for file existence */
  183. #define    X_OK    1    /* Check for execute permission. */
  184. #define    W_OK    2    /* Check for write permission */
  185. #define    R_OK    4    /* Check for read permission */
  186.  
  187. #ifndef RC_INVOKED
  188.  
  189. #ifdef    __cplusplus
  190. extern "C" {
  191. #endif
  192.  
  193. _CRTIMP int __cdecl _access (const char*, int);
  194. _CRTIMP int __cdecl _chsize (int, long);
  195. _CRTIMP int __cdecl _close (int);
  196. _CRTIMP int __cdecl _commit(int);
  197.  
  198. /* NOTE: The only significant bit in unPermissions appears to be bit 7 (0x80),
  199.  *       the "owner write permission" bit (on FAT). */
  200. _CRTIMP int __cdecl _creat (const char*, int);
  201.  
  202. _CRTIMP int __cdecl _dup (int);
  203. _CRTIMP int __cdecl _dup2 (int, int);
  204. _CRTIMP long __cdecl _filelength (int);
  205. _CRTIMP long __cdecl _get_osfhandle (int);
  206. _CRTIMP int __cdecl _isatty (int);
  207.  
  208. /* In a very odd turn of events this function is excluded from those
  209.  * files which define _STREAM_COMPAT. This is required in order to
  210.  * build GNU libio because of a conflict with _eof in streambuf.h
  211.  * line 107. Actually I might just be able to change the name of
  212.  * the enum member in streambuf.h... we'll see. TODO */
  213. #ifndef    _STREAM_COMPAT
  214. _CRTIMP int __cdecl _eof (int);
  215. #endif
  216.  
  217. /* LK_... locking commands defined in sys/locking.h. */
  218. _CRTIMP int __cdecl _locking (int, int, long);
  219.  
  220. _CRTIMP long __cdecl _lseek (int, long, int);
  221.  
  222. /* Optional third argument is unsigned unPermissions. */
  223. _CRTIMP int __cdecl _open (const char*, int, ...);
  224.  
  225. _CRTIMP int __cdecl _open_osfhandle (long, int);
  226. _CRTIMP int __cdecl _pipe (int *, unsigned int, int);
  227. _CRTIMP int __cdecl _read (int, void*, unsigned int);
  228. _CRTIMP int __cdecl _setmode (int, int);
  229.  
  230. /* SH_... flags for nShFlags defined in share.h
  231.  * Optional fourth argument is unsigned unPermissions */
  232. _CRTIMP int __cdecl _sopen (const char*, int, int, ...);
  233.  
  234. _CRTIMP long __cdecl _tell (int);
  235. /* Should umask be in sys/stat.h and/or sys/types.h instead? */
  236. _CRTIMP int __cdecl _umask (int);
  237. _CRTIMP int __cdecl _unlink (const char*);
  238. _CRTIMP int __cdecl _write (int, const void*, unsigned int);
  239.  
  240. /* Wide character versions. Also declared in wchar.h. */
  241. /* Not in crtdll.dll */
  242. #if !defined (_WIO_DEFINED)
  243. #if defined (__MSVCRT__)
  244. _CRTIMP int __cdecl _waccess(const wchar_t*, int);
  245. _CRTIMP int __cdecl _wchmod(const wchar_t*, int);
  246. _CRTIMP int __cdecl _wcreat(const wchar_t*, int);
  247. _CRTIMP long __cdecl _wfindfirst(const wchar_t*, struct _wfinddata_t*);
  248. _CRTIMP int __cdecl _wfindnext(long, struct _wfinddata_t *);
  249. _CRTIMP int __cdecl _wunlink(const wchar_t*);
  250. _CRTIMP int __cdecl _wopen(const wchar_t*, int, ...);
  251. _CRTIMP int __cdecl _wsopen(const wchar_t*, int, int, ...);
  252. _CRTIMP wchar_t * __cdecl _wmktemp(wchar_t*);
  253. _CRTIMP long __cdecl _wfindfirsti64(const wchar_t*, struct _wfinddatai64_t*);
  254. _CRTIMP int __cdecl _wfindnexti64(long, struct _wfinddatai64_t*);
  255. #if __MSVCRT_VERSION__ >= 0x0601
  256. _CRTIMP intptr_t __cdecl _wfindfirst64(const wchar_t*, struct __wfinddata64_t*); 
  257. _CRTIMP intptr_t __cdecl _wfindnext64(intptr_t, struct __wfinddata64_t*);
  258. #endif
  259. #endif /* defined (__MSVCRT__) */
  260. #define _WIO_DEFINED
  261. #endif /* _WIO_DEFINED */
  262.  
  263. #ifndef    _NO_OLDNAMES
  264. /*
  265.  * Non-underscored versions of non-ANSI functions to improve portability.
  266.  * These functions live in libmoldname.a.
  267.  */
  268.  
  269. #ifndef _UWIN
  270. _CRTIMP int __cdecl access (const char*, int);
  271. _CRTIMP int __cdecl chsize (int, long );
  272. _CRTIMP int __cdecl close (int);
  273. _CRTIMP int __cdecl creat (const char*, int);
  274. _CRTIMP int __cdecl dup (int);
  275. _CRTIMP int __cdecl dup2 (int, int);
  276. _CRTIMP int __cdecl eof (int);
  277. _CRTIMP long __cdecl filelength (int);
  278. _CRTIMP int __cdecl isatty (int);
  279. _CRTIMP long __cdecl lseek (int, long, int);
  280. _CRTIMP int __cdecl open (const char*, int, ...);
  281. _CRTIMP int __cdecl read (int, void*, unsigned int);
  282. _CRTIMP int __cdecl setmode (int, int);
  283. _CRTIMP int __cdecl sopen (const char*, int, int, ...);
  284. _CRTIMP long __cdecl tell (int);
  285. _CRTIMP int __cdecl umask (int);
  286. _CRTIMP int __cdecl unlink (const char*);
  287. _CRTIMP int __cdecl write (int, const void*, unsigned int);
  288. #endif /* _UWIN */
  289.  
  290. /* Wide character versions. Also declared in wchar.h. */
  291. /* Where do these live? Not in libmoldname.a nor in libmsvcrt.a */
  292. #if 0
  293. int         waccess(const wchar_t *, int);
  294. int         wchmod(const wchar_t *, int);
  295. int         wcreat(const wchar_t *, int);
  296. long         wfindfirst(wchar_t *, struct _wfinddata_t *);
  297. int         wfindnext(long, struct _wfinddata_t *);
  298. int         wunlink(const wchar_t *);
  299. int         wrename(const wchar_t *, const wchar_t *);
  300. int         wopen(const wchar_t *, int, ...);
  301. int         wsopen(const wchar_t *, int, int, ...);
  302. wchar_t *     wmktemp(wchar_t *);
  303. #endif
  304.  
  305. #endif    /* Not _NO_OLDNAMES */
  306.  
  307. #ifdef    __cplusplus
  308. }
  309. #endif
  310.  
  311. #endif    /* Not RC_INVOKED */
  312.  
  313. #endif    /* _IO_H_ not defined */
  314.