summaryrefslogtreecommitdiff
path: root/src/utils/physfstools.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-28 20:31:09 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-28 20:31:09 +0300
commitbb87f2911b63eaf80e49d689bf52ecf2042ae098 (patch)
tree0778087134ec3c5a2370d417bcadb64a1dc6a9bc /src/utils/physfstools.cpp
parent4415cb66734e67dfcdf8924d354107d27fb70fee (diff)
downloadplus-bb87f2911b63eaf80e49d689bf52ecf2042ae098.tar.gz
plus-bb87f2911b63eaf80e49d689bf52ecf2042ae098.tar.bz2
plus-bb87f2911b63eaf80e49d689bf52ecf2042ae098.tar.xz
plus-bb87f2911b63eaf80e49d689bf52ecf2042ae098.zip
Move from resourcemanager functions related to files into other files.
Diffstat (limited to 'src/utils/physfstools.cpp')
-rw-r--r--src/utils/physfstools.cpp26
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