From 32f791ac7090e1c158e92ad63a418f64055e0c95 Mon Sep 17 00:00:00 2001 From: superp00t Date: Tue, 15 Aug 2023 04:40:59 -0400 Subject: [PATCH] feat(system/file): implemented posix file functions SetPos() and Delete() --- bc/system/file/posix/Stacked.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bc/system/file/posix/Stacked.cpp b/bc/system/file/posix/Stacked.cpp index d00f251..bc5e354 100644 --- a/bc/system/file/posix/Stacked.cpp +++ b/bc/system/file/posix/Stacked.cpp @@ -598,6 +598,32 @@ bool SetAttributes(FileParms* parms) { return true; } +bool SetPos(FileParms* parms) { + auto pos = parms->position; + auto whence = parms->whence; + auto file = parms->stream; + + auto result = ::lseek(file->filefd, static_cast(pos), whence); + + if (result == -1) { + if (errno == ENOSPC) { + BC_FILE_SET_ERROR(BC_FILE_ERROR_NO_SPACE_ON_DEVICE); + return false; + } + + BC_FILE_SET_ERROR(BC_FILE_ERROR_INVALID_ARGUMENT); + return false; + } + + return true; +} + +bool Delete(FileParms* parms) { + File::Path::QuickNative path(parms->filename); + + return ::unlink(path.Str()) != -1; +} + } // namespace Stacked } // namespace System_File } // namespace Blizzard