|
|
|
|
@ -91,7 +91,7 @@ static bool BaseFile_Create(TFileStream * pStream)
|
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) |
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH) |
|
|
|
|
{ |
|
|
|
|
intptr_t handle; |
|
|
|
|
|
|
|
|
|
@ -141,7 +141,7 @@ static bool BaseFile_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD
|
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) |
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH) |
|
|
|
|
{ |
|
|
|
|
struct stat64 fileinfo; |
|
|
|
|
int oflag = (dwStreamFlags & STREAM_FLAG_READ_ONLY) ? O_RDONLY : O_RDWR; |
|
|
|
|
@ -212,7 +212,7 @@ static bool BaseFile_Read(
|
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) |
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH) |
|
|
|
|
{ |
|
|
|
|
ssize_t bytes_read; |
|
|
|
|
|
|
|
|
|
@ -283,7 +283,7 @@ static bool BaseFile_Write(TFileStream * pStream, ULONGLONG * pByteOffset, const
|
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) |
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH) |
|
|
|
|
{ |
|
|
|
|
ssize_t bytes_written; |
|
|
|
|
|
|
|
|
|
@ -350,7 +350,7 @@ static bool BaseFile_Resize(TFileStream * pStream, ULONGLONG NewFileSize)
|
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) |
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH) |
|
|
|
|
{ |
|
|
|
|
if(ftruncate64((intptr_t)pStream->Base.File.hFile, (off64_t)NewFileSize) == -1) |
|
|
|
|
{ |
|
|
|
|
@ -394,7 +394,7 @@ static bool BaseFile_Replace(TFileStream * pStream, TFileStream * pNewStream)
|
|
|
|
|
return (bool)MoveFile(pNewStream->szFileName, pStream->szFileName); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) |
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH) |
|
|
|
|
// "rename" on Linux also works if the target file exists
|
|
|
|
|
if(rename(pNewStream->szFileName, pStream->szFileName) == -1) |
|
|
|
|
{ |
|
|
|
|
@ -414,7 +414,7 @@ static void BaseFile_Close(TFileStream * pStream)
|
|
|
|
|
CloseHandle(pStream->Base.File.hFile); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) |
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH) |
|
|
|
|
close((intptr_t)pStream->Base.File.hFile); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
@ -493,7 +493,7 @@ static bool BaseMap_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD
|
|
|
|
|
return false; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) |
|
|
|
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH) |
|
|
|
|
struct stat64 fileinfo; |
|
|
|
|
intptr_t handle; |
|
|
|
|
bool bResult = false; |
|
|
|
|
@ -506,7 +506,11 @@ static bool BaseMap_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD
|
|
|
|
|
if(fstat64(handle, &fileinfo) != -1) |
|
|
|
|
{ |
|
|
|
|
#if !defined(PLATFORM_AMIGA) |
|
|
|
|
#if defined(PLATFORM_SWITCH) |
|
|
|
|
pStream->Base.Map.pbFile = (LPBYTE)malloc((size_t)fileinfo.st_size); |
|
|
|
|
#else |
|
|
|
|
pStream->Base.Map.pbFile = (LPBYTE)mmap(NULL, (size_t)fileinfo.st_size, PROT_READ, MAP_PRIVATE, handle, 0); |
|
|
|
|
#endif |
|
|
|
|
if(pStream->Base.Map.pbFile != NULL) |
|
|
|
|
{ |
|
|
|
|
// time_t is number of seconds since 1.1.1970, UTC.
|
|
|
|
|
@ -564,10 +568,13 @@ static void BaseMap_Close(TFileStream * pStream)
|
|
|
|
|
UnmapViewOfFile(pStream->Base.Map.pbFile); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if (defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)) && !defined(PLATFORM_AMIGA) |
|
|
|
|
#if (defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)) && !defined(PLATFORM_AMIGA) && !defined(PLATFORM_SWITCH) |
|
|
|
|
//Todo(Amiga): Fix a proper solution for this
|
|
|
|
|
if(pStream->Base.Map.pbFile != NULL) |
|
|
|
|
munmap(pStream->Base.Map.pbFile, (size_t )pStream->Base.Map.FileSize); |
|
|
|
|
#elif defined(PLATFORM_SWITCH) |
|
|
|
|
if(pStream->Base.Map.pbFile != NULL) |
|
|
|
|
free(pStream->Base.Map.pbFile); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
pStream->Base.Map.pbFile = NULL; |
|
|
|
|
|