summaryrefslogtreecommitdiff
path: root/src/fileio.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-12-25 11:26:07 +0000
committerrubidium <rubidium@openttd.org>2007-12-25 11:26:07 +0000
commit429521a7d1f549ba3f9a287885c42f400f5e960f (patch)
tree54a33aa10dd79668da9f46e61e427ace39f5d37f /src/fileio.cpp
parentbf98e25e43c3f6efe207c3dde1732d44c34ac285 (diff)
downloadopenttd-429521a7d1f549ba3f9a287885c42f400f5e960f.tar.xz
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
Diffstat (limited to 'src/fileio.cpp')
-rw-r--r--src/fileio.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 3190013ca..513286dea 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -5,12 +5,12 @@
#include "stdafx.h"
#include "openttd.h"
#include "fileio.h"
-#include "functions.h"
#include "string.h"
#include "variables.h"
#include "debug.h"
#include "fios.h"
#include "core/alloc_func.hpp"
+#include "core/math_func.hpp"
#ifdef WIN32
#include <windows.h>
#else
@@ -764,3 +764,31 @@ void SanitizeFilename(char *filename)
}
}
}
+
+void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
+{
+ FILE *in;
+ byte *mem;
+ size_t len;
+
+ in = fopen(filename, "rb");
+ if (in == NULL) return NULL;
+
+ fseek(in, 0, SEEK_END);
+ len = ftell(in);
+ fseek(in, 0, SEEK_SET);
+ if (len > maxsize || (mem = MallocT<byte>(len + 1)) == NULL) {
+ fclose(in);
+ return NULL;
+ }
+ mem[len] = 0;
+ if (fread(mem, len, 1, in) != 1) {
+ fclose(in);
+ free(mem);
+ return NULL;
+ }
+ fclose(in);
+
+ *lenp = len;
+ return mem;
+}