mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-05-15 05:02:13 -04:00
Improve File error handling. Massive effects...
API is somewhat stolen from Rust std::fs::File. Static factories didn't work out so well, though. Move semantics made my head explode. TODO: Still a lot of places where errors aren't handled, but it's an improvement...
This commit is contained in:
parent
d905c446bf
commit
682a1706a3
18 changed files with 328 additions and 235 deletions
|
@ -23,21 +23,15 @@
|
|||
|
||||
#include "string_format.hpp"
|
||||
|
||||
LogFile::LogFile(
|
||||
const std::string& file_path
|
||||
) : file { file_path, File::openmode::out | File::openmode::ate }
|
||||
{
|
||||
}
|
||||
|
||||
bool LogFile::is_open() const {
|
||||
return file.is_open();
|
||||
}
|
||||
|
||||
bool LogFile::write_entry(const rtc::RTC& datetime, const std::string& entry) {
|
||||
File::Result<size_t> LogFile::write_entry(const rtc::RTC& datetime, const std::string& entry) {
|
||||
std::string timestamp = to_string_timestamp(datetime);
|
||||
return write(timestamp + " " + entry + "\r\n");
|
||||
}
|
||||
|
||||
bool LogFile::write(const std::string& message) {
|
||||
return file.puts(message) && file.sync();
|
||||
File::Result<size_t> LogFile::write(const std::string& message) {
|
||||
auto puts_result = file.puts(message);
|
||||
if( puts_result.is_ok() ) {
|
||||
file.sync();
|
||||
}
|
||||
return puts_result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue