45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
#include <algorithm>
|
|
#include <cstring>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#include "level3_file_system_ce_test.h"
|
|
|
|
namespace wvoec3 {
|
|
|
|
std::map<std::string, std::string> OEMCrypto_Level3CETestFileSystem::files_;
|
|
|
|
ssize_t OEMCrypto_Level3CETestFileSystem::Read(const char *filename,
|
|
void *buffer, size_t size) {
|
|
if (!Exists(filename)) return 0;
|
|
std::string data = files_[std::string(filename)];
|
|
size_t bytes_read = std::min(size, data.size());
|
|
memcpy(buffer, data.data(), bytes_read);
|
|
return bytes_read;
|
|
}
|
|
|
|
ssize_t OEMCrypto_Level3CETestFileSystem::Write(const char *filename,
|
|
const void *buffer,
|
|
size_t size) {
|
|
std::string data(static_cast<const char*>(buffer), size);
|
|
files_[std::string(filename)] = data;
|
|
return size;
|
|
}
|
|
|
|
bool OEMCrypto_Level3CETestFileSystem::Exists(const char *filename) {
|
|
return files_.find(std::string(filename)) != files_.end();
|
|
}
|
|
|
|
ssize_t OEMCrypto_Level3CETestFileSystem::FileSize(const char *filename) {
|
|
if (!Exists(filename)) return -1;
|
|
return files_[std::string(filename)].size();
|
|
}
|
|
|
|
bool OEMCrypto_Level3CETestFileSystem::Remove(const char *filename) {
|
|
if (!Exists(filename)) return false;
|
|
files_.erase(std::string(filename));
|
|
return true;
|
|
}
|
|
|
|
} // namespace wvoec3
|