Added strops and got FileStore test into a useful state.
This commit is contained in:
@@ -4,6 +4,7 @@ add_library(
|
|||||||
WFS
|
WFS
|
||||||
filestore.cpp
|
filestore.cpp
|
||||||
_memops.cpp
|
_memops.cpp
|
||||||
|
_strops.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
|
|||||||
+1
-1
@@ -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
|
* 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
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
|||||||
+1
-1
@@ -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
|
* 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
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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
|
||||||
+1
-1
@@ -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
|
* 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
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
|||||||
+1
-1
@@ -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
|
* 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
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
|||||||
+5
-5
@@ -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
|
* 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
|
* 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 data the contents of the file
|
||||||
* @param dataLen the number of bytes data points to
|
* @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
|
* 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
|
* @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, FsSize_t *size);
|
int read(RecordId id, void *data, FsSize_t *size);
|
||||||
|
|
||||||
static uint8_t version();
|
static uint8_t version();
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ void FileStore<FsSize_t>::init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename FsSize_t>
|
template<typename FsSize_t>
|
||||||
void FileStore<FsSize_t>::write(RecordId id, uint8_t *data, FsSize_t dataLen) {
|
void FileStore<FsSize_t>::write(RecordId id, void *data, FsSize_t dataLen) {
|
||||||
const FsSize_t size = offsetof(FileStore::Record, m_id) + dataLen;
|
const FsSize_t size = offsetof(FileStore::Record, m_id) + dataLen;
|
||||||
auto rec = (Record*) alloc(size);
|
auto rec = (Record*) alloc(size);
|
||||||
rec->dataLen = dataLen;
|
rec->dataLen = dataLen;
|
||||||
@@ -191,7 +191,7 @@ void FileStore<FsSize_t>::write(RecordId id, uint8_t *data, FsSize_t dataLen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename FsSize_t>
|
template<typename FsSize_t>
|
||||||
int FileStore<FsSize_t>::read(RecordId id, uint8_t *data, FsSize_t *size) {
|
int FileStore<FsSize_t>::read(RecordId id, void *data, FsSize_t *size) {
|
||||||
auto rec = getRecord(m_root, id);
|
auto rec = getRecord(m_root, id);
|
||||||
int retval = 1;
|
int retval = 1;
|
||||||
if (rec) {
|
if (rec) {
|
||||||
|
|||||||
+1
-1
@@ -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
|
* 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
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
|||||||
+12
-3
@@ -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
|
* 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
|
* 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 <_strops.hpp>
|
||||||
#include <filestore.hpp>
|
#include <filestore.hpp>
|
||||||
|
|
||||||
using namespace wombat::fs;
|
using namespace wombat::fs;
|
||||||
@@ -15,7 +16,15 @@ int main() {
|
|||||||
char out[6];
|
char out[6];
|
||||||
uint32_t err;
|
uint32_t err;
|
||||||
FileStore32 fs(volume, volume + size, &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;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user