ReactOS  0.4.13-dev-651-g5dbc677
utils.c File Reference
#include "ntvdm.h"
#include <debug.h>
Include dependency graph for utils.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID FileClose (IN HANDLE FileHandle)
 
HANDLE FileOpen (IN PCSTR FileName, OUT PULONG FileSize OPTIONAL)
 
BOOLEAN FileLoadByHandle (IN HANDLE FileHandle, IN PVOID Location, IN ULONG FileSize, OUT PULONG BytesRead)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file utils.c.

Function Documentation

◆ FileClose()

VOID FileClose ( IN HANDLE  FileHandle)

Definition at line 21 of file utils.c.

22 {
24 }
#define CloseHandle
Definition: compat.h:398
HANDLE FileHandle
Definition: stats.c:38

Referenced by DemLoadNTDOSKernel(), DosInitialize(), FileOpen(), LoadBios(), LoadRom(), MountDisk(), OpenRomFile(), and UnmountDisk().

◆ FileLoadByHandle()

BOOLEAN FileLoadByHandle ( IN HANDLE  FileHandle,
IN PVOID  Location,
IN ULONG  FileSize,
OUT PULONG  BytesRead 
)

Definition at line 69 of file utils.c.

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 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HANDLE FileHandle
Definition: stats.c:38
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:409
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define DPRINT1
Definition: precomp.h:8
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

Referenced by DemLoadNTDOSKernel(), DosInitialize(), and LoadRomFileByHandle().

◆ FileOpen()

HANDLE FileOpen ( IN PCSTR  FileName,
OUT PULONG FileSize  OPTIONAL 
)

Definition at line 27 of file utils.c.

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 }
#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
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
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399

Referenced by DemLoadNTDOSKernel(), DosInitialize(), and OpenRomFile().