Repository navigation
Expand file tree
/
Copy pathmodsFileIo.h
More file actions
57 lines (48 loc) · 1.71 KB
/
Copy pathmodsFileIo.h
File metadata and controls
57 lines (48 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Modular-Trackular mods. SPDX-License-Identifier: MIT
//
// The few file operations the mods' settings files need. The firmware implements it
// on CE's FileSystem (mods.cpp); host tests implement it in memory.
#ifndef MODS_MODSFILEIO_H_
#define MODS_MODSFILEIO_H_
#include <cstddef>
#include <cstdint>
namespace mods
{
class FileIo
{
public:
static constexpr size_t kReadFailed = static_cast<size_t>(-1);
virtual ~FileIo() = default;
// Reads up to capacity bytes; returns the file's full size (which may be larger
// than capacity), or kReadFailed if it doesn't exist or can't be read.
virtual size_t read(const char* path, uint8_t* buffer, size_t capacity) = 0;
// Creates or replaces the file.
virtual bool write(const char* path, const uint8_t* data, size_t length) = 0;
virtual void remove(const char* path) = 0;
virtual void makeDir(const char* path) = 0;
// Renames a file; to must not exist. False if it can't (by default: not supported).
virtual bool rename(const char* from, const char* to)
{
(void)from;
(void)to;
return false;
}
virtual bool exists(const char* path)
{
uint8_t byte = 0;
return read(path, &byte, 0) != kReadFailed;
}
// The files in dir whose names end in suffix (any case), sorted, into names: up to count
// of them, nameSize bytes each with the 0 (longer names are left out). Returns how many.
virtual size_t list(const char* dir, const char* suffix, char* names, size_t count, size_t nameSize)
{
(void)dir;
(void)suffix;
(void)names;
(void)count;
(void)nameSize;
return 0;
}
};
} // namespace mods
#endif /* MODS_MODSFILEIO_H_ */