2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: subsystems/mvdm/ntvdm/utils.c
5 * PURPOSE: Utility Functions
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9 /* INCLUDES *******************************************************************/
16 /* PRIVATE FUNCTIONS **********************************************************/
18 /* PUBLIC FUNCTIONS ***********************************************************/
21 FileClose(IN HANDLE FileHandle
)
23 CloseHandle(FileHandle
);
27 FileOpen(IN PCSTR FileName
,
28 OUT PULONG FileSize OPTIONAL
)
34 SetLastError(0); // For debugging purposes
35 hFile
= CreateFileA(FileName
,
40 FILE_ATTRIBUTE_NORMAL
,
42 DPRINT1("File '%s' opening %s ; GetLastError() = %u\n",
43 FileName
, hFile
!= INVALID_HANDLE_VALUE
? "succeeded" : "failed", GetLastError());
45 /* If we failed, bail out */
46 if (hFile
== INVALID_HANDLE_VALUE
) return NULL
;
48 /* OK, we have a handle to the file */
51 * Retrieve the size of the file. In NTVDM we will handle files
52 * of maximum 1Mb so we can largely use GetFileSize only.
54 ulFileSize
= GetFileSize(hFile
, NULL
);
55 if (ulFileSize
== INVALID_FILE_SIZE
&& GetLastError() != ERROR_SUCCESS
)
57 /* We failed, bail out */
58 DPRINT1("Error when retrieving file size, or size too large (%d)\n", ulFileSize
);
63 /* Success, return file handle and size if needed */
64 if (FileSize
) *FileSize
= ulFileSize
;
69 FileLoadByHandle(IN HANDLE FileHandle
,
76 /* Attempt to load the file into memory */
77 SetLastError(0); // For debugging purposes
78 Success
= !!ReadFile(FileHandle
,
79 Location
, // REAL_TO_PHYS(LocationRealPtr),
83 DPRINT1("File loading %s ; GetLastError() = %u\n", Success
? "succeeded" : "failed", GetLastError());