1 /* $Id: rw.c,v 1.11 2000/04/03 21:54:35 dwelch Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/rw.c
6 * PURPOSE: Read/write functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
12 /* INCLUDES ****************************************************************/
14 #include <ddk/ntddk.h>
20 #include <kernel32/kernel32.h>
23 /* FUNCTIONS ****************************************************************/
25 WINBOOL STDCALL
WriteFile(HANDLE hFile
,
27 DWORD nNumberOfBytesToWrite
,
28 LPDWORD lpNumberOfBytesWritten
,
29 LPOVERLAPPED lpOverLapped
)
34 IO_STATUS_BLOCK IIosb
;
35 PIO_STATUS_BLOCK IoStatusBlock
;
36 PLARGE_INTEGER ptrOffset
;
38 DPRINT("WriteFile(hFile %x)\n",hFile
);
40 if (IsConsoleHandle(hFile
))
42 return(WriteConsoleA(hFile
,
44 nNumberOfBytesToWrite
,
45 lpNumberOfBytesWritten
,
49 if (lpOverLapped
!= NULL
)
51 Offset
.u
.LowPart
= lpOverLapped
->Offset
;
52 Offset
.u
.HighPart
= lpOverLapped
->OffsetHigh
;
53 lpOverLapped
->Internal
= STATUS_PENDING
;
54 hEvent
= lpOverLapped
->hEvent
;
55 IoStatusBlock
= (PIO_STATUS_BLOCK
)lpOverLapped
;
61 IoStatusBlock
= &IIosb
;
65 errCode
= NtWriteFile(hFile
,
71 nNumberOfBytesToWrite
,
74 if (!NT_SUCCESS(errCode
))
76 SetLastError(RtlNtStatusToDosError(errCode
));
77 DPRINT("WriteFile() failed\n");
80 if (lpNumberOfBytesWritten
!= NULL
)
82 *lpNumberOfBytesWritten
= IoStatusBlock
->Information
;
84 DPRINT("WriteFile() succeeded\n");
90 WINBOOL STDCALL
ReadFile(HANDLE hFile
,
92 DWORD nNumberOfBytesToRead
,
93 LPDWORD lpNumberOfBytesRead
,
94 LPOVERLAPPED lpOverLapped
)
99 IO_STATUS_BLOCK IIosb
;
100 PIO_STATUS_BLOCK IoStatusBlock
;
101 PLARGE_INTEGER ptrOffset
;
103 DbgPrint("ReadFile(hFile %x)\n", hFile
);
105 if (IsConsoleHandle(hFile
))
107 return(ReadConsoleA(hFile
,
109 nNumberOfBytesToRead
,
114 if (lpOverLapped
!= NULL
)
116 Offset
.u
.LowPart
= lpOverLapped
->Offset
;
117 Offset
.u
.HighPart
= lpOverLapped
->OffsetHigh
;
118 lpOverLapped
->Internal
= STATUS_PENDING
;
119 hEvent
= lpOverLapped
->hEvent
;
120 IoStatusBlock
= (PIO_STATUS_BLOCK
)lpOverLapped
;
126 IoStatusBlock
= &IIosb
;
129 errCode
= NtReadFile(hFile
,
135 nNumberOfBytesToRead
,
139 if (errCode
!= STATUS_PENDING
&& lpNumberOfBytesRead
!= NULL
)
141 *lpNumberOfBytesRead
= IoStatusBlock
->Information
;
144 if (!NT_SUCCESS(errCode
))
146 SetLastError(RtlNtStatusToDosError(errCode
));
152 VOID
ApcRoutine(PVOID ApcContext
,
153 struct _IO_STATUS_BLOCK
* IoStatusBlock
,
154 ULONG NumberOfBytesTransfered
)
157 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
=
158 (LPOVERLAPPED_COMPLETION_ROUTINE
)ApcContext
;
160 dwErrorCode
= RtlNtStatusToDosError( IoStatusBlock
->Status
);
161 lpCompletionRoutine(dwErrorCode
,
162 NumberOfBytesTransfered
,
163 (LPOVERLAPPED
)IoStatusBlock
);
172 DWORD nNumberOfBytesToWrite
,
173 LPOVERLAPPED lpOverLapped
,
174 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
178 LARGE_INTEGER Offset
;
180 PIO_STATUS_BLOCK IoStatusBlock
;
181 PLARGE_INTEGER ptrOffset
;
183 DPRINT("WriteFileEx(hFile %x)\n",hFile
);
185 if (lpOverLapped
== NULL
)
188 Offset
.u
.LowPart
= lpOverLapped
->Offset
;
189 Offset
.u
.HighPart
= lpOverLapped
->OffsetHigh
;
190 lpOverLapped
->Internal
= STATUS_PENDING
;
191 IoStatusBlock
= (PIO_STATUS_BLOCK
)lpOverLapped
;
194 errCode
= NtWriteFile(hFile
,
200 nNumberOfBytesToWrite
,
203 if (!NT_SUCCESS(errCode
))
205 SetLastError(RtlNtStatusToDosError(errCode
));
206 DPRINT("WriteFileEx() failed\n");
210 DPRINT("WriteFileEx() succeeded\n");
214 WINBOOL STDCALL
ReadFileEx(HANDLE hFile
,
216 DWORD nNumberOfBytesToRead
,
217 LPOVERLAPPED lpOverLapped
,
218 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
)
220 LARGE_INTEGER Offset
;
222 PIO_STATUS_BLOCK IoStatusBlock
;
223 PLARGE_INTEGER ptrOffset
;
225 if (lpOverLapped
== NULL
)
228 Offset
.u
.LowPart
= lpOverLapped
->Offset
;
229 Offset
.u
.HighPart
= lpOverLapped
->OffsetHigh
;
230 lpOverLapped
->Internal
= STATUS_PENDING
;
231 IoStatusBlock
= (PIO_STATUS_BLOCK
)lpOverLapped
;
234 errCode
= NtReadFile(hFile
,
240 nNumberOfBytesToRead
,
244 if (!NT_SUCCESS(errCode
))
246 SetLastError(RtlNtStatusToDosError(errCode
));