mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-03 12:27:21 +12:00
[FS] Implement SetSize
This commit is contained in:
parent
82b986bbc0
commit
075a244dd0
3 changed files with 51 additions and 0 deletions
|
@ -18,6 +18,12 @@
|
|||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <io.h> // For _chsize_s
|
||||
#else
|
||||
#include <unistd.h> // For ftruncate
|
||||
#endif
|
||||
|
||||
class IOFile {
|
||||
FILE* handle = nullptr;
|
||||
static inline std::filesystem::path appData = ""; // Directory for holding app data. AppData on Windows
|
||||
|
@ -112,5 +118,19 @@ public:
|
|||
appData = dir;
|
||||
}
|
||||
|
||||
// Sets the size of the file to "size" and returns whether it succeeded or not
|
||||
bool setSize(std::uint64_t size) {
|
||||
if (!isOpen()) return false;
|
||||
bool success;
|
||||
|
||||
#ifdef WIN32
|
||||
success = _chsize_s(_fileno(handle), size) == 0;
|
||||
#else
|
||||
success = ftruncate(fileno(handle), size) == 0;
|
||||
#endif
|
||||
fflush(handle);
|
||||
return success;
|
||||
}
|
||||
|
||||
static std::filesystem::path getAppData() { return IOFile::appData; }
|
||||
};
|
|
@ -127,6 +127,7 @@ private:
|
|||
void writeFile(u32 messagePointer, Handle file);
|
||||
void getFileSize(u32 messagePointer, Handle file);
|
||||
void openLinkFile(u32 messagePointer, Handle file);
|
||||
void setFileSize(u32 messagePointer, Handle file);
|
||||
void setFilePriority(u32 messagePointer, Handle file);
|
||||
|
||||
// Directory operations
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue