Fix WIN32 file read.
This commit is contained in:
		
							parent
							
								
									a6d7b948d4
								
							
						
					
					
						commit
						30c586d37d
					
				
							
								
								
									
										33
									
								
								Arena.cc
								
								
								
								
							
							
						
						
									
										33
									
								
								Arena.cc
								
								
								
								
							| 
						 | 
					@ -187,9 +187,8 @@ Arena::Open(const char *path)
 | 
				
			||||||
	size_t		 fSize;
 | 
						size_t		 fSize;
 | 
				
			||||||
	size_t		 fRemaining;
 | 
						size_t		 fRemaining;
 | 
				
			||||||
	auto		*cursor = this->store;
 | 
						auto		*cursor = this->store;
 | 
				
			||||||
	OVERLAPPED	 overlap;
 | 
						OVERLAPPED	 overlap = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::cout << "CreateFileA\n";
 | 
					 | 
				
			||||||
	fHandle = CreateFileA(
 | 
						fHandle = CreateFileA(
 | 
				
			||||||
	    (LPSTR)path,
 | 
						    (LPSTR)path,
 | 
				
			||||||
	    GENERIC_READ,
 | 
						    GENERIC_READ,
 | 
				
			||||||
| 
						 | 
					@ -203,26 +202,36 @@ Arena::Open(const char *path)
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::cout << "GetFileSizeEx\n";
 | 
						if (SetFilePointer(fHandle, 0, 0, FILE_BEGIN) != 0) {
 | 
				
			||||||
	if (!GetFileSizeEx(fHandle, reinterpret_cast<PLARGE_INTEGER>(&fSize))) {
 | 
							displayWinErr("SetFilePointer");
 | 
				
			||||||
 | 
							CloseHandle(fHandle);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (GetFileSizeEx(fHandle, reinterpret_cast<PLARGE_INTEGER>(&fSize)) != TRUE) {
 | 
				
			||||||
		displayWinErr("GetFileSizeEx");
 | 
							displayWinErr("GetFileSizeEx");
 | 
				
			||||||
		CloseHandle(fHandle);
 | 
							CloseHandle(fHandle);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->SetAlloc(fSize);
 | 
						this->SetAlloc(fSize);
 | 
				
			||||||
 | 
						cursor = this->NewCursor();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						this->store[0] = 1;
 | 
				
			||||||
	fRemaining = fSize;
 | 
						fRemaining = fSize;
 | 
				
			||||||
	while (fRemaining != 0) {
 | 
						while (fRemaining != 0) {
 | 
				
			||||||
		std::cout << "ReadFile\n";
 | 
					 | 
				
			||||||
		overlap.Offset = (fSize - fRemaining);
 | 
							overlap.Offset = (fSize - fRemaining);
 | 
				
			||||||
		if (ReadFile(fHandle, cursor, fSize,
 | 
							if (ReadFile(fHandle, cursor, fSize-1,
 | 
				
			||||||
			     &fRead,
 | 
								     &fRead,
 | 
				
			||||||
			     &overlap) != TRUE) {
 | 
								     &overlap) != TRUE) {
 | 
				
			||||||
			displayWinErr("ReadFile");
 | 
								auto errorCode = GetLastError();
 | 
				
			||||||
			CloseHandle(fHandle);
 | 
								if (errorCode != ERROR_HANDLE_EOF) {
 | 
				
			||||||
			this->Destroy();
 | 
									displayWinErr("ReadFile");
 | 
				
			||||||
			return -1;
 | 
									CloseHandle(fHandle);
 | 
				
			||||||
 | 
									this->Destroy();
 | 
				
			||||||
 | 
									return -1;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		cursor += fRead;
 | 
							cursor += fRead;
 | 
				
			||||||
| 
						 | 
					@ -239,7 +248,6 @@ Arena::Create(const char *path, size_t fileSize, DWORD mode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	HANDLE 		 fHandle;
 | 
						HANDLE 		 fHandle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::cout << "Create::CreateFileA\n";
 | 
					 | 
				
			||||||
	fHandle = CreateFileA(
 | 
						fHandle = CreateFileA(
 | 
				
			||||||
	    (LPSTR)path,
 | 
						    (LPSTR)path,
 | 
				
			||||||
	    GENERIC_READ|GENERIC_WRITE,
 | 
						    GENERIC_READ|GENERIC_WRITE,
 | 
				
			||||||
| 
						 | 
					@ -253,7 +261,6 @@ Arena::Create(const char *path, size_t fileSize, DWORD mode)
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::cout << "SetFileValidData\n";
 | 
					 | 
				
			||||||
	if (SetFileValidData(fHandle, fileSize) != fileSize) {
 | 
						if (SetFileValidData(fHandle, fileSize) != fileSize) {
 | 
				
			||||||
		displayWinErr("SetFileValidData");
 | 
							displayWinErr("SetFileValidData");
 | 
				
			||||||
		CloseHandle(fHandle);
 | 
							CloseHandle(fHandle);
 | 
				
			||||||
| 
						 | 
					@ -379,7 +386,7 @@ operator<<(std::ostream &os, Arena &arena)
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
Arena::Write(const char *path)
 | 
					Arena::Write(const char *path)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	FILE *arenaFile = NULL;
 | 
						FILE *arenaFile = nullptr;
 | 
				
			||||||
	int retc = -1;
 | 
						int retc = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__posix__) || defined(__linux__)
 | 
					#if defined(__posix__) || defined(__linux__)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								Arena.h
								
								
								
								
							
							
						
						
									
										2
									
								
								Arena.h
								
								
								
								
							| 
						 | 
					@ -116,7 +116,7 @@ public:
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int MemoryMap(int memFileDes, size_t memSize)
 | 
						int MemoryMap(int memFileDes, size_t memSize)
 | 
				
			||||||
	{ throw NotImplemented("WIN32"); }
 | 
						{ (void)memFileDes; (void)memSize; throw NotImplemented("WIN32"); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	/// Create creates a new file, truncating it if it already exists. On
 | 
						/// Create creates a new file, truncating it if it already exists. On
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue