[*] Address *some* build issues under Linux. Interim port progress
This commit is contained in:
parent
62e3490d9f
commit
5a96a71949
@ -90,7 +90,6 @@ namespace Aurora::Memory
|
||||
}
|
||||
|
||||
this->base = temp;
|
||||
this->length = this->length;
|
||||
this->allocSize = this->length;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,11 @@
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
#if defined(AURORA_COMPILER_CLANG)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wswitch"
|
||||
#endif
|
||||
|
||||
namespace Aurora::Memory
|
||||
{
|
||||
bool ByteBuffer::WriteString(const AuString &string, EStringType type, Locale::ECodePage codepage)
|
||||
@ -134,4 +139,8 @@ namespace Aurora::Memory
|
||||
// TODO: ...
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(AURORA_COMPILER_CLANG)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
@ -8,7 +8,14 @@
|
||||
#pragma once
|
||||
#include <Source/RuntimeInternal.hpp>
|
||||
#include "Debug.hpp"
|
||||
#include <DbgHelp.h>
|
||||
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
#include <DbgHelp.h>
|
||||
#endif
|
||||
|
||||
#if defined(AURORA_COMPILER_CLANG)
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
namespace Aurora::Debug
|
||||
{
|
||||
|
@ -1,3 +1,10 @@
|
||||
/***
|
||||
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: FileStream.Unix.cpp
|
||||
Date: 2021-6-12
|
||||
Author: Reece
|
||||
***/
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#define _LARGEFILE64_SOURCE
|
||||
|
||||
@ -34,8 +41,7 @@ namespace Aurora::IO::FS
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
LogWarn("PosixLseek63 IO Error %i", ret);
|
||||
SysPushErrorIO("PosixLseek63: %i", ret);
|
||||
SysPushErrorIO("PosixLseek63 IO Error: %i", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -84,8 +90,7 @@ namespace Aurora::IO::FS
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
LogWarn("PosixRead IO Error %i", ret);
|
||||
SysPushErrorIO("PosixRead: %i", ret);
|
||||
SysPushErrorIO("PosixRead IO Error: %i", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -103,8 +108,7 @@ namespace Aurora::IO::FS
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
LogWarn("PosixWrite IO Error %i", ret);
|
||||
SysPushErrorIO("PosixWrite: %i", ret);
|
||||
SysPushErrorIO("PosixWrite IO Error: %i", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -122,52 +126,64 @@ namespace Aurora::IO::FS
|
||||
Close();
|
||||
}
|
||||
|
||||
void PosixFileStream::Init(int handle, const AuString &path)
|
||||
bool PosixFileStream::Init(int handle, const AuString &path)
|
||||
{
|
||||
handle_ = handle;
|
||||
path_ = path;
|
||||
AuCtorCode_t code;
|
||||
|
||||
this->handle_ = handle;
|
||||
this->path_ = AuTryConstruct<AuString>(code, path);
|
||||
if (!code)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: spinlock
|
||||
AuUInt64 PosixFileStream::GetOffset()
|
||||
{
|
||||
if (handle_ == -1)
|
||||
AU_LOCK_GUARD(this->spinlock_);
|
||||
|
||||
if (this->handle_ == -1)
|
||||
{
|
||||
SysPushErrorUninitialized();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return PosixGetOffset(handle_);
|
||||
return PosixGetOffset(this->handle_);
|
||||
}
|
||||
|
||||
// ...
|
||||
bool PosixFileStream::SetOffset(AuUInt64 offset)
|
||||
{
|
||||
if (handle_ == -1)
|
||||
AU_LOCK_GUARD(this->spinlock_);
|
||||
|
||||
if (this->handle_ == -1)
|
||||
{
|
||||
SysPushErrorUninitialized();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return PosixSetOffset(handle_, offset);
|
||||
return PosixSetOffset(this->handle_, offset);
|
||||
}
|
||||
|
||||
// ...
|
||||
AuUInt64 PosixFileStream::GetLength()
|
||||
{
|
||||
if (handle_ == -1)
|
||||
AU_LOCK_GUARD(this->spinlock_);
|
||||
|
||||
if (this->handle_ == -1)
|
||||
{
|
||||
SysPushErrorUninitialized();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return PosixGetLength(handle_);
|
||||
return PosixGetLength(this->handle_);
|
||||
}
|
||||
|
||||
// ...
|
||||
bool PosixFileStream::Read(const Memory::MemoryViewStreamWrite ¶meters)
|
||||
{
|
||||
if (handle_ == -1)
|
||||
AU_LOCK_GUARD(this->spinlock_);
|
||||
|
||||
if (this->handle_ == -1)
|
||||
{
|
||||
SysPushErrorUninitialized();
|
||||
return 0;
|
||||
@ -179,7 +195,7 @@ namespace Aurora::IO::FS
|
||||
{
|
||||
AuUInt32 read;
|
||||
|
||||
int blockSize = std::min(kFileCopyBlock, length);
|
||||
int blockSize = AuMin(kFileCopyBlock, length);
|
||||
|
||||
if (!PosixRead(handle_, &reinterpret_cast<char *>(parameters.ptr)[offset], blockSize, &read))
|
||||
{
|
||||
@ -205,24 +221,25 @@ namespace Aurora::IO::FS
|
||||
return true;
|
||||
}
|
||||
|
||||
// ...
|
||||
bool PosixFileStream::Write(const Memory::MemoryViewStreamRead ¶meters)
|
||||
{
|
||||
if (handle_ == -1)
|
||||
AU_LOCK_GUARD(this->spinlock_);
|
||||
|
||||
if (this->handle_ == -1)
|
||||
{
|
||||
SysPushErrorUninitialized();
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto length = parameters.length;
|
||||
AuUInt length = parameters.length;
|
||||
AuUInt offset {0};
|
||||
while (length)
|
||||
{
|
||||
AuUInt32 written;
|
||||
|
||||
int blockSize = std::min(kFileCopyBlock, length);
|
||||
int blockSize = AuMin(AuUInt(kFileCopyBlock), length);
|
||||
|
||||
if (!PosixWrite(handle_, &reinterpret_cast<const char *>(parameters.ptr)[offset], blockSize, &written))
|
||||
if (!PosixWrite(this->handle_, &reinterpret_cast<const char *>(parameters.ptr)[offset], blockSize, &written))
|
||||
{
|
||||
SysPushErrorNested("File Error: {}", path_);
|
||||
return false;
|
||||
@ -230,7 +247,6 @@ namespace Aurora::IO::FS
|
||||
|
||||
if (written != blockSize)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
SysPushErrorNested("File Error: {}", path_);
|
||||
break;
|
||||
}
|
||||
@ -252,20 +268,30 @@ namespace Aurora::IO::FS
|
||||
{
|
||||
int handle;
|
||||
|
||||
if ((handle = std::exchange(handle_, -1)) != -1)
|
||||
if ((handle = std::exchange(this->handle_, -1)) != -1)
|
||||
{
|
||||
::close(handle);
|
||||
}
|
||||
|
||||
if (AuExchange(this->bMadeTemporary, false))
|
||||
{
|
||||
::unlink(this->path_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void PosixFileStream::Flush()
|
||||
{
|
||||
fsync(handle_);
|
||||
::fsync(this->handle_);
|
||||
}
|
||||
|
||||
|
||||
void PosixFileStream::WriteEoS()
|
||||
{
|
||||
ftruncate(handle_, GetOffset());
|
||||
::ftruncate(this->handle_, GetOffset());
|
||||
}
|
||||
|
||||
void PosixFileStream::MakeTemporary()
|
||||
{
|
||||
this->bMadeTemporary = true;
|
||||
}
|
||||
|
||||
static IFileStream *OpenNew(const AuString &path, bool read)
|
||||
@ -281,7 +307,6 @@ namespace Aurora::IO::FS
|
||||
|
||||
if (fileHandle < 0)
|
||||
{
|
||||
LogWarn("Couldn't open file: {}", path);
|
||||
SysPushErrorIO("Couldn't open file: {}", path);
|
||||
return nullptr;
|
||||
}
|
||||
@ -289,11 +314,16 @@ namespace Aurora::IO::FS
|
||||
auto stream = _new PosixFileStream();
|
||||
if (!stream)
|
||||
{
|
||||
close(fileHandle);
|
||||
::close(fileHandle);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!stream->Init(fileHandle, pathex))
|
||||
{
|
||||
delete stream;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
stream->Init(fileHandle, pathex);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/***
|
||||
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: FileStream.Win32.hpp
|
||||
File: FileStream.Unix.hpp
|
||||
Date: 2021-6-12
|
||||
Author: Reece
|
||||
***/
|
||||
@ -16,7 +16,7 @@ namespace Aurora::IO::FS
|
||||
public:
|
||||
~PosixFileStream();
|
||||
|
||||
void Init(int handle, const AuString &path);
|
||||
bool Init(int handle, const AuString &path);
|
||||
|
||||
AuUInt64 GetOffset() override;
|
||||
bool SetOffset(AuUInt64 offset) override;
|
||||
@ -26,11 +26,14 @@ namespace Aurora::IO::FS
|
||||
void Close() override;
|
||||
void Flush() override;
|
||||
void WriteEoS() override;
|
||||
void MakeTemporary() override;
|
||||
|
||||
private:
|
||||
|
||||
int handle_ = -1;
|
||||
AuString path_;
|
||||
AuThreadPrimitives::SpinLock spinlock_;
|
||||
bool bMadeTemporary {};
|
||||
};
|
||||
}
|
||||
#endif
|
@ -44,6 +44,7 @@
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
Loading…
Reference in New Issue
Block a user