:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / include / crtdll / io.h
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 <colin@bird.fu.is.saga-u.ac.jp>
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  *  DISCLAMED. This includes but is not limited to warranties of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * $Revision$
22  * $Author$
23  * $Date$
24  *
25  */
26 /* Appropriated for Reactos Crtdll by Ariadne */
27 /* added D_OK */
28 /* changed get_osfhandle and open_osfhandle */
29 /* added fileno as macro */
30 #ifndef _IO_H_
31 #define _IO_H_
32
33 #ifndef __STRICT_ANSI__
34
35 #include <crtdll/sys/types.h>
36
37 #include <crtdll/sys/stat.h>
38
39
40 /* We need the definition of FILE anyway... */
41 #include <crtdll/stdio.h>
42
43 /* MSVC's io.h contains the stuff from dir.h, so I will too.
44  * NOTE: This also defines off_t, the file offset type, through
45  * and inclusion of sys/types.h */
46 #include <crtdll/dir.h>
47
48 /* TODO: Maximum number of open handles has not been tested, I just set
49  * it the same as FOPEN_MAX. */
50 #define HANDLE_MAX      FOPEN_MAX
51
52
53 /* Some defines for _access nAccessMode (MS doesn't define them, but
54  * it doesn't seem to hurt to add them). */
55 #define F_OK    0       /* Check for file existence */
56 #define W_OK    2       /* Check for write permission */
57 #define R_OK    4       /* Check for read permission */
58 /* TODO: Is this safe? X_OK not supported directly... */
59 #define X_OK    R_OK    /* Check for execute permission */
60 #define D_OK    0x10
61
62
63
64 #ifdef  __cplusplus
65 extern "C" {
66 #endif
67
68 int             _access (const char* szFileName, int nAccessMode);
69 int             _chsize (int nHandle, long lnNewSize);
70 int             _close (int nHandle);
71 int             _commit(int _fd);
72 int             _creat (const char* szFileName, int nAccessMode);
73 int             _dup (int nHandle);
74 int             _dup2 (int nOldHandle, int nNewHandle);
75 long            _filelength (int nHandle);
76 int             _fileno (FILE* fileGetHandle);
77 void*           _get_osfhandle (int nHandle);
78 int             _isatty (int nHandle);
79
80 /* In a very odd turn of events this function is excluded from those
81  * files which define _STREAM_COMPAT. This is required in order to
82  * build GNU libio because of a conflict with _eof in streambuf.h
83  * line 107. Actually I might just be able to change the name of
84  * the enum member in streambuf.h... we'll see. TODO */
85 #ifndef _STREAM_COMPAT
86 int             _eof (int nHandle);
87 #endif
88
89 /* LK_... locking commands defined in sys/locking.h. */
90 int             _locking (int nHandle, int nCmd, long lnLockRegionLength);
91
92 off_t           _lseek(int _fd, off_t _offset, int _whence);
93 int             _open (const char* szFileName, int nFlags, ...);
94 int             _open_osfhandle (void *lnOSHandle, int nFlags);
95 int             _pipe (int *naHandles, unsigned int unSize, int nMode);
96 size_t          _read(int _fd, void *_buf, size_t _nbyte);
97
98 /* SH_... flags for nFlag defined in share.h */
99 int             _sopen (char* szFileName, int nAccess, int nFlag, int nMode);
100
101 long            _tell (int nHandle);
102 unsigned        _umask (unsigned unMode);
103 int             _unlink (const char* szFileName);
104 size_t          _write(int _fd, const void *_buf, size_t _nbyte);
105
106 #ifndef _NO_OLDNAMES
107 /*
108  * Non-underscored versions of non-ANSI functions to improve portability.
109  * These functions live in libmoldname.a.
110  */
111
112 #define access          _access
113 #define chsize          _chsize 
114 #define close           _close
115 #define creat           _creat
116 #define dup             _dup
117 #define dup2            _dup2
118 #define eof             _eof
119 #define filelength      _filelength
120 #define fileno(f)       ((f)->_file)
121 #define isatty          _isatty
122 #define lseek           _lseek
123 #define open            _open
124 #define read            _read
125 #define sopen(path,access,shflag,mode)  _open((path), (access)|(shflag), (mode))
126 #define tell(file)                      _lseek(_file, 0, SEEK_CUR)
127 #define umask           _umask
128 #define unlink          _unlink
129 #define write           _write
130                 
131
132 #endif  /* Not _NO_OLDNAMES */
133
134 #ifdef  __cplusplus
135 }
136 #endif
137
138 #endif  /* Not strict ANSI */
139
140 #endif  /* _IO_H_ not defined */