From 083711ceb211a7f34003ef76d0e44ab0f73bb54c Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 18 Feb 2016 21:33:38 -0800 Subject: [PATCH] Add File::open(), use inside File::open_for_append(). --- firmware/application/file.cpp | 8 ++++++-- firmware/application/file.hpp | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/firmware/application/file.cpp b/firmware/application/file.cpp index 4898ee74d..3695063dc 100644 --- a/firmware/application/file.cpp +++ b/firmware/application/file.cpp @@ -25,9 +25,13 @@ File::~File() { close(); } -bool File::open_for_append(const std::string& file_path) { +bool File::open(const std::string& file_path) { const auto open_result = f_open(&f, file_path.c_str(), FA_WRITE | FA_OPEN_ALWAYS); - if( open_result == FR_OK ) { + return (open_result == FR_OK); +} + +bool File::open_for_append(const std::string& file_path) { + if( open(file_path) ) { const auto seek_result = f_lseek(&f, f_size(&f)); if( seek_result == FR_OK ) { return true; diff --git a/firmware/application/file.hpp b/firmware/application/file.hpp index 533bc4562..17ac5a7cd 100644 --- a/firmware/application/file.hpp +++ b/firmware/application/file.hpp @@ -31,6 +31,7 @@ class File { public: ~File(); + bool open(const std::string& file_path); bool open_for_append(const std::string& file_path); bool close();