- nhttpd: add option to appent to file in write_to_file()

This commit is contained in:
TangoCash
2022-11-07 21:21:38 +01:00
committed by Thilo Graf
parent 4e1277de42
commit 593003c241
2 changed files with 3 additions and 3 deletions

View File

@@ -250,9 +250,9 @@ std::string string_tolower(std::string str) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// write string to a file // write string to a file
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool write_to_file(std::string filename, std::string content) { bool write_to_file(std::string filename, std::string content, bool append) {
FILE *fd = NULL; FILE *fd = NULL;
if ((fd = fopen(filename.c_str(), "w")) != NULL) // open file if ((fd = fopen(filename.c_str(), append ? "a" : "w")) != NULL) // open file
{ {
fwrite(content.c_str(), content.length(), 1, fd); fwrite(content.c_str(), content.length(), 1, fd);
fflush(fd); // flush and close file fflush(fd); // flush and close file

View File

@@ -35,7 +35,7 @@ bool ySplitStringLast(std::string str, std::string delimiter, std::string& left,
CStringArray ySplitStringVector(std::string str, std::string delimiter); CStringArray ySplitStringVector(std::string str, std::string delimiter);
bool nocase_compare (char c1, char c2); bool nocase_compare (char c1, char c2);
std::string timeString(time_t time); std::string timeString(time_t time);
bool write_to_file(std::string filename, std::string content); bool write_to_file(std::string filename, std::string content, bool append=false);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// JSON Helpers // JSON Helpers