Add File seek support.

This commit is contained in:
Jared Boone 2016-05-01 11:29:44 -07:00
parent c5cae1034e
commit 80f94cbc29
2 changed files with 13 additions and 0 deletions

View File

@ -63,6 +63,17 @@ bool File::write(const void* const data, const size_t bytes_to_write) {
return (result == FR_OK) && (bytes_written == bytes_to_write);
}
uint64_t File::seek(const uint64_t new_position) {
const auto old_position = f_tell(&f);
if( f_lseek(&f, new_position) != FR_OK ) {
f_close(&f);
}
if( f_tell(&f) != new_position ) {
f_close(&f);
}
return old_position;
}
bool File::puts(const std::string& string) {
const auto result = f_puts(string.c_str(), &f);
return (result >= 0);

View File

@ -51,6 +51,8 @@ public:
bool read(void* const data, const size_t bytes_to_read);
bool write(const void* const data, const size_t bytes_to_write);
uint64_t seek(const uint64_t new_position);
template<size_t N>
bool write(const std::array<uint8_t, N>& data) {
return write(data.data(), N);