Navit SVN

/work/compile/navit/src/navit/support/libc/io.h

00001 /*
00002  * io.h
00003  * This file has no copyright assigned and is placed in the Public Domain.
00004  * This file is a part of the mingw-runtime package.
00005  * No warranty is given; refer to the file DISCLAIMER within the package.
00006  *
00007  * System level I/O functions and types.
00008  *
00009  */
00010 #ifndef _IO_H_
00011 #define _IO_H_
00012 
00013 /* All the headers include this file. */
00014 #include <_mingw.h>
00015 
00016 /* MSVC's io.h contains the stuff from dir.h, so I will too.
00017  * NOTE: This also defines off_t, the file offset type, through
00018  *       an inclusion of sys/types.h */
00019 
00020 #include <sys/types.h>  /* To get time_t.  */
00021 
00022 /*
00023  * Attributes of files as returned by _findfirst et al.
00024  */
00025 #define _A_NORMAL       0x00000000
00026 #define _A_RDONLY       0x00000001
00027 #define _A_HIDDEN       0x00000002
00028 #define _A_SYSTEM       0x00000004
00029 #define _A_VOLID        0x00000008
00030 #define _A_SUBDIR       0x00000010
00031 #define _A_ARCH         0x00000020
00032 
00033 
00034 #ifndef RC_INVOKED
00035 
00036 #ifndef _INTPTR_T_DEFINED
00037 #define _INTPTR_T_DEFINED
00038 #ifdef _WIN64
00039   typedef __int64 intptr_t;
00040 #else
00041   typedef int intptr_t;
00042 #endif
00043 #endif
00044 
00045 #ifndef _FSIZE_T_DEFINED
00046 typedef unsigned long   _fsize_t;
00047 #define _FSIZE_T_DEFINED
00048 #endif
00049 
00050 /*
00051  * The maximum length of a file name. You should use GetVolumeInformation
00052  * instead of this constant. But hey, this works.
00053  * Also defined in stdio.h.
00054  */
00055 #ifndef FILENAME_MAX
00056 #define FILENAME_MAX    (260)
00057 #endif
00058 
00059 /*
00060  * The following structure is filled in by _findfirst or _findnext when
00061  * they succeed in finding a match.
00062  */
00063 #ifndef _FINDDATA_T_DEFINED
00064 struct _finddata_t
00065 {
00066         unsigned        attrib;         /* Attributes, see constants above. */
00067         time_t          time_create;
00068         time_t          time_access;    /* always midnight local time */
00069         time_t          time_write;
00070         _fsize_t        size;
00071         char            name[FILENAME_MAX];     /* may include spaces. */
00072 };
00073 
00074 #ifndef __COREDLL__
00075 
00076 struct _finddatai64_t {
00077     unsigned    attrib;
00078     time_t      time_create;
00079     time_t      time_access;
00080     time_t      time_write;
00081     __int64     size;
00082     char        name[FILENAME_MAX];
00083 };
00084 
00085 #if __MSVCRT_VERSION__ >= 0x0601
00086 struct __finddata64_t {
00087         unsigned    attrib;
00088         __time64_t  time_create;
00089         __time64_t  time_access;
00090         __time64_t  time_write;
00091 /* 8 bytes are returned so it can't be _fsize_t */
00092         __int64    size;
00093          char       name[FILENAME_MAX];
00094 };
00095 #endif
00096 
00097 #endif
00098 
00099 #define _FINDDATA_T_DEFINED
00100 #endif  /* _FINDDATA_T_DEFINED */
00101 
00102 #ifndef _WFINDDATA_T_DEFINED
00103 struct _wfinddata_t {
00104         unsigned        attrib;
00105         time_t          time_create;    /* -1 for FAT file systems */
00106         time_t          time_access;    /* -1 for FAT file systems */
00107         time_t          time_write;
00108         _fsize_t        size;
00109         wchar_t         name[FILENAME_MAX];     /* may include spaces. */
00110 };
00111 
00112 #ifndef __COREDLL__
00113 
00114 struct _wfinddatai64_t {
00115     unsigned    attrib;
00116     time_t      time_create;
00117     time_t      time_access;
00118     time_t      time_write;
00119     __int64     size;
00120     wchar_t     name[FILENAME_MAX];
00121 };
00122 
00123 #if __MSVCRT_VERSION__ >= 0x0601
00124 struct __wfinddata64_t {
00125         unsigned    attrib;
00126         __time64_t  time_create;
00127         __time64_t  time_access;
00128         __time64_t  time_write;
00129 /* 8 bytes are returned so it can't be _fsize_t */
00130         __int64    size;
00131         wchar_t     name[FILENAME_MAX];
00132 };
00133 #endif
00134 
00135 #endif /* __COREDLL__ */
00136 
00137 #define _WFINDDATA_T_DEFINED
00138 #endif
00139 
00140 
00141 #ifdef  __cplusplus
00142 extern "C" {
00143 #endif
00144 
00145 /*
00146  * Functions for searching for files. _findfirst returns -1 if no match
00147  * is found. Otherwise it returns a handle to be used in _findnext and
00148  * _findclose calls. _findnext also returns -1 if no match could be found,
00149  * and 0 if a match was found. Call _findclose when you are finished.
00150  */
00151 /*  FIXME: Should these all use intptr_t, as per recent MSDN docs?  */
00152 _CRTIMP long __cdecl __MINGW_NOTHROW _findfirst (const char*, struct _finddata_t*);
00153 _CRTIMP int __cdecl __MINGW_NOTHROW _findnext (long, struct _finddata_t*);
00154 _CRTIMP int __cdecl __MINGW_NOTHROW _findclose (long);
00155 
00156 #ifndef UNDER_CE
00157 _CRTIMP int __cdecl __MINGW_NOTHROW _chdir (const char*);
00158 _CRTIMP char* __cdecl __MINGW_NOTHROW _getcwd (char*, int);
00159 _CRTIMP char* __cdecl __MINGW_NOTHROW _mktemp (char*);
00160 #endif
00161 _CRTIMP int __cdecl __MINGW_NOTHROW _mkdir (const char*);
00162 _CRTIMP int __cdecl __MINGW_NOTHROW _rmdir (const char*);
00163 _CRTIMP int __cdecl __MINGW_NOTHROW _chmod (const char*, int);
00164 
00165 #ifdef __MSVCRT__
00166 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _filelengthi64(int);
00167 _CRTIMP long __cdecl __MINGW_NOTHROW _findfirsti64(const char*, struct _finddatai64_t*);
00168 _CRTIMP int __cdecl __MINGW_NOTHROW _findnexti64(long, struct _finddatai64_t*);
00169 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _lseeki64(int, __int64, int);
00170 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _telli64(int);
00171 /* These require newer versions of msvcrt.dll (6.1 or higher). */ 
00172 #if __MSVCRT_VERSION__ >= 0x0601
00173 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _findfirst64(const char*, struct __finddata64_t*);
00174 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _findnext64(intptr_t, struct __finddata64_t*); 
00175 #endif /* __MSVCRT_VERSION__ >= 0x0601 */
00176 #ifndef __NO_MINGW_LFS
00177 __CRT_INLINE off64_t lseek64 (int, off64_t, int);
00178 __CRT_INLINE off64_t lseek64 (int fd, off64_t offset, int whence)
00179 {
00180   return _lseeki64(fd, (__int64) offset, whence);
00181 }
00182 #endif
00183 
00184 #endif /* __MSVCRT__ */
00185 
00186 #ifndef _NO_OLDNAMES
00187 
00188 #ifndef _UWIN
00189 #ifndef UNDER_CE
00190 _CRTIMP int __cdecl __MINGW_NOTHROW chdir (const char*);
00191 _CRTIMP char* __cdecl __MINGW_NOTHROW getcwd (char*, int);
00192 _CRTIMP char* __cdecl __MINGW_NOTHROW mktemp (char*);
00193 #endif
00194 _CRTIMP int __cdecl __MINGW_NOTHROW mkdir (const char*);
00195 _CRTIMP int __cdecl __MINGW_NOTHROW rmdir (const char*);
00196 _CRTIMP int __cdecl __MINGW_NOTHROW chmod (const char*, int);
00197 #endif /* _UWIN */
00198 
00199 #endif /* Not _NO_OLDNAMES */
00200 
00201 #ifdef  __cplusplus
00202 }
00203 #endif
00204 
00205 #endif  /* Not RC_INVOKED */
00206 
00207 /* TODO: Maximum number of open handles has not been tested, I just set
00208  * it the same as FOPEN_MAX. */
00209 #define HANDLE_MAX      FOPEN_MAX
00210 
00211 /* Some defines for _access nAccessMode (MS doesn't define them, but
00212  * it doesn't seem to hurt to add them). */
00213 #define F_OK    0       /* Check for file existence */
00214 /* Well maybe it does hurt.  On newer versions of MSVCRT, an access mode
00215    of 1 causes invalid parameter error. */   
00216 #define X_OK    1       /* MS access() doesn't check for execute permission. */
00217 #define W_OK    2       /* Check for write permission */
00218 #define R_OK    4       /* Check for read permission */
00219 
00220 #ifndef RC_INVOKED
00221 
00222 #ifdef  __cplusplus
00223 extern "C" {
00224 #endif
00225 
00226 _CRTIMP int __cdecl __MINGW_NOTHROW _access (const char*, int);
00227 _CRTIMP int __cdecl __MINGW_NOTHROW _chsize (int, long);
00228 _CRTIMP int __cdecl __MINGW_NOTHROW _close (int);
00229 _CRTIMP int __cdecl __MINGW_NOTHROW _commit(int);
00230 
00231 /* NOTE: The only significant bit in unPermissions appears to be bit 7 (0x80),
00232  *       the "owner write permission" bit (on FAT). */
00233 _CRTIMP int __cdecl __MINGW_NOTHROW _creat (const char*, int);
00234 
00235 _CRTIMP int __cdecl __MINGW_NOTHROW _dup (int);
00236 _CRTIMP int __cdecl __MINGW_NOTHROW _dup2 (int, int);
00237 _CRTIMP long __cdecl __MINGW_NOTHROW _filelength (int);
00238 _CRTIMP long __cdecl __MINGW_NOTHROW _get_osfhandle (int);
00239 _CRTIMP int __cdecl __MINGW_NOTHROW _isatty (int);
00240 
00241 /* In a very odd turn of events this function is excluded from those
00242  * files which define _STREAM_COMPAT. This is required in order to
00243  * build GNU libio because of a conflict with _eof in streambuf.h
00244  * line 107. Actually I might just be able to change the name of
00245  * the enum member in streambuf.h... we'll see. TODO */
00246 #ifndef _STREAM_COMPAT
00247 _CRTIMP int __cdecl __MINGW_NOTHROW _eof (int);
00248 #endif
00249 
00250 /* LK_... locking commands defined in sys/locking.h. */
00251 _CRTIMP int __cdecl __MINGW_NOTHROW _locking (int, int, long);
00252 
00253 _CRTIMP long __cdecl __MINGW_NOTHROW _lseek (int, long, int);
00254 
00255 /* Optional third argument is unsigned unPermissions. */
00256 _CRTIMP int __cdecl __MINGW_NOTHROW _open (const char*, int, ...);
00257 
00258 #ifndef __COREDLL__
00259 _CRTIMP int __cdecl __MINGW_NOTHROW _open_osfhandle (long, int);
00260 _CRTIMP int __cdecl __MINGW_NOTHROW _pipe (int *, unsigned int, int);
00261 #endif /* __COREDLL__ */
00262 _CRTIMP int __cdecl __MINGW_NOTHROW _read (int, void*, unsigned int);
00263 #ifndef __COREDLL__
00264 _CRTIMP int __cdecl __MINGW_NOTHROW _setmode (int, int);
00265 /* MS puts remove & rename (but not wide versions) in io.h as well
00266    as in stdio.h. */
00267 _CRTIMP int __cdecl __MINGW_NOTHROW     remove (const char*);
00268 #endif
00269 _CRTIMP int __cdecl __MINGW_NOTHROW     rename (const char*, const char*);
00270 #ifndef __COREDLL__
00271 /* SH_... flags for nShFlags defined in share.h
00272  * Optional fourth argument is unsigned unPermissions */
00273 _CRTIMP int __cdecl __MINGW_NOTHROW _sopen (const char*, int, int, ...);
00274 
00275 _CRTIMP long __cdecl __MINGW_NOTHROW _tell (int);
00276 /* Should umask be in sys/stat.h and/or sys/types.h instead? */
00277 _CRTIMP int __cdecl __MINGW_NOTHROW _umask (int);
00278 #endif /* __COREDLL__ */
00279 _CRTIMP int __cdecl __MINGW_NOTHROW _unlink (const char*);
00280 _CRTIMP int __cdecl __MINGW_NOTHROW _write (int, const void*, unsigned int);
00281 
00282 /* Wide character versions. Also declared in wchar.h. */
00283 /* Not in crtdll.dll */
00284 #if !defined (_WIO_DEFINED)
00285 #if defined (__MSVCRT__)
00286 _CRTIMP int __cdecl __MINGW_NOTHROW _waccess(const wchar_t*, int);
00287 _CRTIMP int __cdecl __MINGW_NOTHROW _wchmod(const wchar_t*, int);
00288 _CRTIMP int __cdecl __MINGW_NOTHROW _wcreat(const wchar_t*, int);
00289 #endif
00290 #if defined (__MSVCRT__) || defined (__COREDLL__)
00291 _CRTIMP long __cdecl __MINGW_NOTHROW _wfindfirst(const wchar_t*, struct _wfinddata_t*);
00292 _CRTIMP int __cdecl __MINGW_NOTHROW _wfindnext(long, struct _wfinddata_t *);
00293 _CRTIMP int __cdecl __MINGW_NOTHROW _wopen(const wchar_t*, int, ...);
00294 #endif
00295 #if defined (__MSVCRT__)
00296 _CRTIMP int __cdecl __MINGW_NOTHROW _wunlink(const wchar_t*);
00297 _CRTIMP int __cdecl __MINGW_NOTHROW _wsopen(const wchar_t*, int, int, ...);
00298 _CRTIMP wchar_t * __cdecl __MINGW_NOTHROW _wmktemp(wchar_t*);
00299 _CRTIMP long __cdecl __MINGW_NOTHROW _wfindfirsti64(const wchar_t*, struct _wfinddatai64_t*);
00300 _CRTIMP int __cdecl __MINGW_NOTHROW _wfindnexti64(long, struct _wfinddatai64_t*);
00301 #if __MSVCRT_VERSION__ >= 0x0601
00302 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wfindfirst64(const wchar_t*, struct __wfinddata64_t*); 
00303 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wfindnext64(intptr_t, struct __wfinddata64_t*);
00304 #endif
00305 #endif /* defined (__MSVCRT__) */
00306 #define _WIO_DEFINED
00307 #endif /* _WIO_DEFINED */
00308 
00309 #ifndef _NO_OLDNAMES
00310 /*
00311  * Non-underscored versions of non-ANSI functions to improve portability.
00312  * These functions live in libmoldname.a.
00313  */
00314 
00315 #ifndef _UWIN
00316 _CRTIMP int __cdecl __MINGW_NOTHROW access (const char*, int);
00317 _CRTIMP int __cdecl __MINGW_NOTHROW chsize (int, long );
00318 _CRTIMP int __cdecl __MINGW_NOTHROW close (int);
00319 #ifndef __COREDLL__
00320 _CRTIMP int __cdecl __MINGW_NOTHROW creat (const char*, int);
00321 _CRTIMP int __cdecl __MINGW_NOTHROW dup (int);
00322 _CRTIMP int __cdecl __MINGW_NOTHROW dup2 (int, int);
00323 _CRTIMP int __cdecl __MINGW_NOTHROW eof (int);
00324 _CRTIMP long __cdecl __MINGW_NOTHROW filelength (int);
00325 #endif /* __COREDLL__ */
00326 _CRTIMP int __cdecl __MINGW_NOTHROW isatty (int);
00327 _CRTIMP long __cdecl __MINGW_NOTHROW lseek (int, long, int);
00328 _CRTIMP int __cdecl __MINGW_NOTHROW open (const char*, int, ...);
00329 _CRTIMP int __cdecl __MINGW_NOTHROW read (int, void*, unsigned int);
00330 #ifndef __COREDLL__
00331 _CRTIMP int __cdecl __MINGW_NOTHROW setmode (int, int);
00332 _CRTIMP int __cdecl __MINGW_NOTHROW sopen (const char*, int, int, ...);
00333 _CRTIMP long __cdecl __MINGW_NOTHROW tell (int);
00334 _CRTIMP int __cdecl __MINGW_NOTHROW umask (int);
00335 #endif /* __COREDLL__ */
00336 _CRTIMP int __cdecl __MINGW_NOTHROW unlink (const char*);
00337 _CRTIMP int __cdecl __MINGW_NOTHROW write (int, const void*, unsigned int);
00338 #endif /* _UWIN */
00339 
00340 #ifdef __USE_MINGW_ACCESS
00341 /*  Old versions of MSVCRT access() just ignored X_OK, while the version
00342     shipped with Vista, returns an error code.  This will restore the
00343     old behaviour  */
00344 static inline int __mingw_access (const char* __fname, int __mode)
00345   { return  _access (__fname, __mode & ~X_OK); }
00346 #define access(__f,__m)  __mingw_access (__f, __m)
00347 #endif
00348 
00349 /* Wide character versions. Also declared in wchar.h. */
00350 /* Where do these live? Not in libmoldname.a nor in libmsvcrt.a */
00351 #if 0
00352 int             waccess(const wchar_t *, int);
00353 int             wchmod(const wchar_t *, int);
00354 int             wcreat(const wchar_t *, int);
00355 long            wfindfirst(wchar_t *, struct _wfinddata_t *);
00356 int             wfindnext(long, struct _wfinddata_t *);
00357 int             wunlink(const wchar_t *);
00358 int             wrename(const wchar_t *, const wchar_t *);
00359 int             wopen(const wchar_t *, int, ...);
00360 int             wsopen(const wchar_t *, int, int, ...);
00361 wchar_t *       wmktemp(wchar_t *);
00362 #endif
00363 
00364 #endif  /* Not _NO_OLDNAMES */
00365 
00366 #ifdef  __cplusplus
00367 }
00368 #endif
00369 
00370 #endif  /* Not RC_INVOKED */
00371 
00372 #endif  /* _IO_H_ not defined */