mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
IOFile: Allow multiple opens on the same object
This commit is contained in:
parent
6588f6764f
commit
b7ce987487
2 changed files with 8 additions and 2 deletions
|
@ -8,7 +8,7 @@ class IOFile {
|
||||||
static inline std::filesystem::path appData = ""; // Directory for holding app data. AppData on Windows
|
static inline std::filesystem::path appData = ""; // Directory for holding app data. AppData on Windows
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IOFile() {}
|
IOFile() : handle(nullptr) {}
|
||||||
IOFile(FILE* handle) : handle(handle) {}
|
IOFile(FILE* handle) : handle(handle) {}
|
||||||
IOFile(const std::filesystem::path& path, const char* permissions = "rb");
|
IOFile(const std::filesystem::path& path, const char* permissions = "rb");
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include <unistd.h> // For ftruncate
|
#include <unistd.h> // For ftruncate
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
IOFile::IOFile(const std::filesystem::path& path, const char* permissions) { open(path, permissions); }
|
IOFile::IOFile(const std::filesystem::path& path, const char* permissions) : handle(nullptr) { open(path, permissions); }
|
||||||
|
|
||||||
bool IOFile::open(const std::filesystem::path& path, const char* permissions) {
|
bool IOFile::open(const std::filesystem::path& path, const char* permissions) {
|
||||||
const auto str = path.string(); // For some reason converting paths directly with c_str() doesn't work
|
const auto str = path.string(); // For some reason converting paths directly with c_str() doesn't work
|
||||||
|
@ -29,6 +29,12 @@ bool IOFile::open(const std::filesystem::path& path, const char* permissions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IOFile::open(const char* filename, const char* permissions) {
|
bool IOFile::open(const char* filename, const char* permissions) {
|
||||||
|
// If this IOFile is already bound to an open file descriptor, release the file descriptor
|
||||||
|
// To avoid leaking it and/or erroneously locking the file
|
||||||
|
if (isOpen()) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
handle = std::fopen(filename, permissions);
|
handle = std::fopen(filename, permissions);
|
||||||
return isOpen();
|
return isOpen();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue