Browse Source

remove mman.h dependency on Switch platform

pull/497/head
rsn8887 7 years ago committed by Anders Jenbo
parent
commit
8e84ae0159
  1. 25
      3rdParty/StormLib/src/FileStream.cpp
  2. 25
      3rdParty/StormLib/src/StormPort.h

25
3rdParty/StormLib/src/FileStream.cpp vendored

@ -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;

25
3rdParty/StormLib/src/StormPort.h vendored

@ -151,6 +151,29 @@
#endif
#if !defined(PLATFORM_DEFINED) && defined(__SWITCH__)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <assert.h>
#include <errno.h>
#ifndef __BIG_ENDIAN__
#define PLATFORM_LITTLE_ENDIAN
#endif
#define PLATFORM_SWITCH
#define PLATFORM_DEFINED
#endif
//-----------------------------------------------------------------------------
// Assumption: we are not on Windows nor Macintosh, so this must be linux *grin*
@ -264,7 +287,7 @@
#endif
// Platform-specific error codes for UNIX-based platforms
#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)
#define ERROR_SUCCESS 0
#define ERROR_FILE_NOT_FOUND ENOENT
#define ERROR_ACCESS_DENIED EPERM

Loading…
Cancel
Save