Removed stdlib dependency.

This commit is contained in:
2016-06-05 19:28:56 -05:00
parent 44ac7ca684
commit 02e25000e1
2 changed files with 4 additions and 6 deletions
+3 -5
View File
@@ -5,7 +5,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include <stdlib.h>
#include "_memops.hpp" #include "_memops.hpp"
#include "filestore.hpp" #include "filestore.hpp"
@@ -15,7 +14,7 @@ namespace fs {
uint32_t FileStore::version = 0; uint32_t FileStore::version = 0;
uint8_t *initFs(uint8_t *buffer, size_t size, bool hasDirectories) { uint8_t *initFs(uint8_t *buffer, size_t size, bool hasDirectories) {
auto fs = (MemFsHeader*) (buffer ? buffer : malloc(size)); auto fs = (MemFsHeader*) buffer;
fs->version = FileStore::version; fs->version = FileStore::version;
return (uint8_t*) fs; return (uint8_t*) fs;
} }
@@ -65,13 +64,12 @@ void FileStore::write(RecordId id, uint8_t *data, MemFsPtr dataLen) {
insert(m_root, rec); insert(m_root, rec);
} }
int FileStore::read(RecordId id, uint8_t **data, MemFsPtr *size) { int FileStore::read(RecordId id, uint8_t *data, MemFsPtr *size) {
auto rec = getRecord(m_root, id); auto rec = getRecord(m_root, id);
int retval = 1; int retval = 1;
if (rec) { if (rec) {
*size = rec->dataLen; *size = rec->dataLen;
*data = (uint8_t*) malloc(*size); memcpy(data, ptr<uint8_t*>(rec->m_data), *size);
memcpy(*data, ptr<uint8_t*>(rec->m_data), *size);
retval = 0; retval = 0;
} }
return retval; return retval;
+1 -1
View File
@@ -85,7 +85,7 @@ class FileStore {
* @param size pointer to a value that will be assigned the size of data * @param size pointer to a value that will be assigned the size of data
* @return 0 if read is a success * @return 0 if read is a success
*/ */
int read(RecordId id, uint8_t **data, MemFsPtr *size); int read(RecordId id, uint8_t *data, MemFsPtr *size);
private: private:
/** /**