ReactOS  0.4.13-dev-982-g9853eab
utils.c
Go to the documentation of this file.
1 /*
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)
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "ntvdm.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* PRIVATE FUNCTIONS **********************************************************/
17 
18 /* PUBLIC FUNCTIONS ***********************************************************/
19 
20 VOID
22 {
24 }
25 
26 HANDLE
29 {
30  HANDLE hFile;
31  ULONG ulFileSize;
32 
33  /* Open the file */
34  SetLastError(0); // For debugging purposes
38  NULL,
41  NULL);
42  DPRINT1("File '%s' opening %s ; GetLastError() = %u\n",
43  FileName, hFile != INVALID_HANDLE_VALUE ? "succeeded" : "failed", GetLastError());
44 
45  /* If we failed, bail out */
46  if (hFile == INVALID_HANDLE_VALUE) return NULL;
47 
48  /* OK, we have a handle to the file */
49 
50  /*
51  * Retrieve the size of the file. In NTVDM we will handle files
52  * of maximum 1Mb so we can largely use GetFileSize only.
53  */
54  ulFileSize = GetFileSize(hFile, NULL);
55  if (ulFileSize == INVALID_FILE_SIZE && GetLastError() != ERROR_SUCCESS)
56  {
57  /* We failed, bail out */
58  DPRINT1("Error when retrieving file size, or size too large (%d)\n", ulFileSize);
60  return NULL;
61  }
62 
63  /* Success, return file handle and size if needed */
64  if (FileSize) *FileSize = ulFileSize;
65  return hFile;
66 }
67 
68 BOOLEAN
70  IN PVOID Location,
73 {
75 
76  /* Attempt to load the file into memory */
77  SetLastError(0); // For debugging purposes
79  Location, // REAL_TO_PHYS(LocationRealPtr),
80  FileSize,
81  BytesRead,
82  NULL);
83  DPRINT1("File loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
84 
85  return Success;
86 }
87 
88 /* EOF */
#define IN
Definition: typedefs.h:38
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define INVALID_FILE_SIZE
Definition: winbase.h:529
VOID FileClose(IN HANDLE FileHandle)
Definition: utils.c:21
#define FILE_SHARE_READ
Definition: compat.h:125
HANDLE FileHandle
Definition: stats.c:38
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define SetLastError(x)
Definition: compat.h:409
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
HANDLE FileOpen(IN PCSTR FileName, OUT PULONG FileSize OPTIONAL)
Definition: utils.c:27
unsigned int * PULONG
Definition: retypes.h:1
#define DPRINT1
Definition: precomp.h:8
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN FileLoadByHandle(IN HANDLE FileHandle, IN PVOID Location, IN ULONG FileSize, OUT PULONG BytesRead)
Definition: utils.c:69
const char * PCSTR
Definition: typedefs.h:51
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68