diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cdf6bc8c7..b7a03954d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,7 @@ add_library( WFS filestore.cpp _memops.cpp + _strops.cpp ) install( diff --git a/src/_memops.cpp b/src/_memops.cpp index d8bef7b3c..072d05fa0 100644 --- a/src/_memops.cpp +++ b/src/_memops.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 gtalent2@gmail.com + * Copyright 2015 - 2016 gtalent2@gmail.com * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/src/_memops.hpp b/src/_memops.hpp index a534de22f..44696bbf3 100644 --- a/src/_memops.hpp +++ b/src/_memops.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 gtalent2@gmail.com + * Copyright 2015 - 2016 gtalent2@gmail.com * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/src/_strops.cpp b/src/_strops.cpp new file mode 100644 index 000000000..31be2124d --- /dev/null +++ b/src/_strops.cpp @@ -0,0 +1,26 @@ +/* + * Copyright 2015 - 2016 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * 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/. + */ +namespace wombat { +namespace fs { + +int strcmp(const char *str1, const char *str2) { + auto retval = 0; + for (int i = 0; str1[i] && str2[i]; i++) { + if (str1[i] < str2[i]) { + retval = -1; + break; + } else if (str1[i] > str2[i]) { + retval = 1; + } + } + return retval; +} + +} +} + diff --git a/src/_strops.hpp b/src/_strops.hpp new file mode 100644 index 000000000..a90aac2f0 --- /dev/null +++ b/src/_strops.hpp @@ -0,0 +1,19 @@ +/* + * Copyright 2015 - 2016 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * 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/. + */ +#ifndef WOMBAT_FS_STROPS_HPP +#define WOMBAT_FS_STROPS_HPP + +namespace wombat { +namespace fs { + +int strcmp(const char *str1, const char *str2); + +} +} + +#endif diff --git a/src/_types.hpp b/src/_types.hpp index c0903ff81..6ffda99fb 100644 --- a/src/_types.hpp +++ b/src/_types.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 gtalent2@gmail.com + * Copyright 2015 - 2016 gtalent2@gmail.com * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/src/filestore.cpp b/src/filestore.cpp index aad8eb401..ad429e611 100644 --- a/src/filestore.cpp +++ b/src/filestore.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 gtalent2@gmail.com + * Copyright 2015 - 2016 gtalent2@gmail.com * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/src/filestore.hpp b/src/filestore.hpp index 2665a1a7f..5ab4c3fa3 100644 --- a/src/filestore.hpp +++ b/src/filestore.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 gtalent2@gmail.com + * Copyright 2015 - 2016 gtalent2@gmail.com * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -75,7 +75,7 @@ class FileStore { * @param data the contents of the file * @param dataLen the number of bytes data points to */ - void write(RecordId id, uint8_t *data, FsSize_t dataLen); + void write(RecordId id, void *data, FsSize_t dataLen); /** * Reads the "file" at the given id. You are responsible for freeing @@ -85,7 +85,7 @@ class FileStore { * @param size pointer to a value that will be assigned the size of data * @return 0 if read is a success */ - int read(RecordId id, uint8_t *data, FsSize_t *size); + int read(RecordId id, void *data, FsSize_t *size); static uint8_t version(); @@ -183,7 +183,7 @@ void FileStore::init() { } template -void FileStore::write(RecordId id, uint8_t *data, FsSize_t dataLen) { +void FileStore::write(RecordId id, void *data, FsSize_t dataLen) { const FsSize_t size = offsetof(FileStore::Record, m_id) + dataLen; auto rec = (Record*) alloc(size); rec->dataLen = dataLen; @@ -191,7 +191,7 @@ void FileStore::write(RecordId id, uint8_t *data, FsSize_t dataLen) { } template -int FileStore::read(RecordId id, uint8_t *data, FsSize_t *size) { +int FileStore::read(RecordId id, void *data, FsSize_t *size) { auto rec = getRecord(m_root, id); int retval = 1; if (rec) { diff --git a/test/format.cpp b/test/format.cpp index afef2e242..0167319d5 100644 --- a/test/format.cpp +++ b/test/format.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 gtalent2@gmail.com + * Copyright 2015 - 2016 gtalent2@gmail.com * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/test/fsstore.cpp b/test/fsstore.cpp index 82394265d..9db49b041 100644 --- a/test/fsstore.cpp +++ b/test/fsstore.cpp @@ -1,10 +1,11 @@ /* - * Copyright 2015 gtalent2@gmail.com + * Copyright 2015 - 2016 gtalent2@gmail.com * * This Source Code Form is subject to the terms of the Mozilla Public * 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/. */ +#include <_strops.hpp> #include using namespace wombat::fs; @@ -15,7 +16,15 @@ int main() { char out[6]; uint32_t err; FileStore32 fs(volume, volume + size, &err); - fs.write(42, (uint8_t*) "Hello", 6); - err = fs.read(42, (uint8_t*) out, nullptr); + + fs.write(42, (void*) "Hello", 6); + + err = fs.read(42, (char*) out, nullptr); + if (err) { + return err; + } + + err = strcmp("Hello", out); + return err; }