diff options
Diffstat (limited to 'src/utils/physfstools.cpp')
-rw-r--r-- | src/utils/physfstools.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/utils/physfstools.cpp b/src/utils/physfstools.cpp index 58be77f0e..1ab1aaa25 100644 --- a/src/utils/physfstools.cpp +++ b/src/utils/physfstools.cpp @@ -20,6 +20,8 @@ #include "utils/physfstools.h" +#include "logger.h" + #include <iostream> #include <unistd.h> @@ -134,4 +136,28 @@ namespace PhysFs { return PHYSFS_mkdir(dirname); } + + void *loadFile(const std::string &fileName, int &fileSize) + { + // Attempt to open the specified file using PhysicsFS + PHYSFS_file *const file = PhysFs::openRead(fileName.c_str()); + + if (!file) + { + logger->log("Warning: Failed to load %s: %s", + fileName.c_str(), PHYSFS_getLastError()); + return nullptr; + } + + logger->log("Loaded %s/%s", PhysFs::getRealDir(fileName.c_str()), + fileName.c_str()); + + fileSize = static_cast<int>(PHYSFS_fileLength(file)); + // Allocate memory and load the file + void *const buffer = calloc(fileSize, 1); + PHYSFS_read(file, buffer, 1, fileSize); + PHYSFS_close(file); + + return buffer; + } } // namespace PhysFs |