Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change fileSetContent() to return a result #1657

Merged
merged 6 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Sming/SmingCore/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,22 @@ void fileClearLastError(file_t fd)
SPIFFS_clearerr(&_filesystemStorageHandle);
}

void fileSetContent(const String& fileName, const String& content)
int fileSetContent(const String& fileName, const String& content)
{
fileSetContent(fileName, content.c_str());
return fileSetContent(fileName, content.c_str());
}

void fileSetContent(const String& fileName, const char* content)
int fileSetContent(const String& fileName, const char* content)
{
int res;

file_t file = fileOpen(fileName.c_str(), eFO_CreateNewAlways | eFO_WriteOnly);
fileWrite(file, content, strlen(content));
if(file < 0) {
return file;
}
res = fileWrite(file, content, strlen(content));
fileClose(file);
return res;
}

uint32_t fileGetSize(const String& fileName)
Expand Down
8 changes: 6 additions & 2 deletions Sming/SmingCore/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,23 @@ void fileClearLastError(file_t fd);
/** @brief Create or replace file with defined content
* @param fileName Name of file to create or replace
* @param content Pointer to c-string containing content to populate file with
* @retval int Positive integer represents the numbers of bytes written.
* @retval int Negative integer represents the error code of last file system operation.
* @note This function creates a new file or replaces an existing file and
populates the file with the content of a c-string buffer.
Remember to terminate your c-string buffer with a null (0).
*/
void fileSetContent(const String& fileName, const char* content);
int fileSetContent(const String& fileName, const char* content);

/** @brief Create or replace file with defined content
* @param fileName Name of file to create or replace
* @param content String containing content to populate file with
* @retval int Positive integer represents the numbers of bytes written.
* @retval int Negative integer represents the error code of last file system operation.
* @note This function creates a new file or replaces an existing file and
populates the file with the content of a string.
*/
void fileSetContent(const String& fileName, const String& content);
int fileSetContent(const String& fileName, const String& content);

/** @brief Get size of file
* @param fileName Name of file
Expand Down