Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
FatFsFileReader.cpp
Go to the documentation of this file.
2#include <cstring>
3#include <ff_stdio.h>
4
6
10
11bool FatFsFileReader::open(const std::string& path) {
12 file = ff_fopen(path.c_str(), "r");
13 isOpen = (file != nullptr);
14 return isOpen;
15}
16
17
19 if (isOpen && file) {
20 ff_fclose(file);
21 file = nullptr;
22 isOpen = false;
23 }
24}
25
26
27bool FatFsFileReader::readLine(char* outLine, size_t maxLen) {
28 if (!isOpen || !file || maxLen == 0) return false;
29
30
31 size_t count = 0;
32 int ch;
33
34 while (count < maxLen - 1) {
35 ch = ff_fgetc(file);
36 if (ch == EOF) break;
37 if (ch == '\n') break;
38 if (ch != '\r') {
39 outLine[count++] = static_cast<char>(ch);
40 }
41 }
42
43 if (count == 0 && ch == EOF) return false;
44
45 outLine[count] = '\0';
46 return true;
47}
48
49
void close() override
Closes the file.
~FatFsFileReader() override
bool open(const std::string &path)
Opens a file for reading.
bool readLine(char *outLine, size_t maxLen) override
Reads a single line into the provided buffer.