diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-09 15:04:29 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-09 15:04:29 +0000 |
commit | 4a0a3305191b3be51542bed5c382edae3aba7058 (patch) | |
tree | 9761a5cbdc6b77cd28081ad75382c005e8837ca0 /src/resourcemanager.cpp | |
parent | 304a338d53fbb717ed8fd220848c9ee486a3c699 (diff) | |
download | manaserv-4a0a3305191b3be51542bed5c382edae3aba7058.tar.gz manaserv-4a0a3305191b3be51542bed5c382edae3aba7058.tar.bz2 manaserv-4a0a3305191b3be51542bed5c382edae3aba7058.tar.xz manaserv-4a0a3305191b3be51542bed5c382edae3aba7058.zip |
Added new scripting interface and Lua engine.
Diffstat (limited to 'src/resourcemanager.cpp')
-rw-r--r-- | src/resourcemanager.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/resourcemanager.cpp b/src/resourcemanager.cpp index 41039ab1..d45e96e4 100644 --- a/src/resourcemanager.cpp +++ b/src/resourcemanager.cpp @@ -161,12 +161,14 @@ ResourceManager::loadFile(const std::string &fileName, int &fileSize) fileSize = PHYSFS_fileLength(file); // Allocate memory and load the file - void *buffer = malloc(fileSize); + void *buffer = malloc(fileSize + 1); PHYSFS_read(file, buffer, 1, fileSize); // Close the file and let the user deallocate the memory PHYSFS_close(file); + // Add a trailing nul character, so that the file can be used as a string + ((char *)buffer)[fileSize] = 0; return buffer; } @@ -183,10 +185,6 @@ ResourceManager::loadTextFile(const std::string &fileName) return lines; } - // Reallocate and include terminating 0 character - fileContents = (char*)realloc(fileContents, contentsLength + 1); - fileContents[contentsLength] = '\0'; - // Tokenize and add each line separately char *line = strtok(fileContents, "\n"); while (line != NULL) |