Skip to content
Snippets Groups Projects
Commit 42e7d5fb authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

fwritelog() will now auto-close a log file when it reaches the max size

parent cff51443
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3221 passed
......@@ -417,7 +417,7 @@ static void event_log_msg(log_msg_t* msg)
if(msg->repeated)
Line += " [x" + AnsiString(msg->repeated + 1) + "]";
Line+="\n";
fwritelog(AnsiString(Line).c_str(),Line.Length(),LogStream);
fwritelog(&MainForm->cfg, AnsiString(Line).c_str(), Line.Length(), &LogStream);
}
}
}
......
......@@ -237,9 +237,15 @@ FILE* fopenlog(scfg_t* cfg, const char* path)
return fp;
}
size_t fwritelog(void* buf, size_t size, FILE* fp)
// Write to a log file and may close it if reached max size
size_t fwritelog(scfg_t* cfg, void* buf, size_t size, FILE** fp)
{
return fwrite(buf, 1, size, fp);
size_t result = fwrite(buf, 1, size, *fp);
if(cfg->max_log_size && ftell(*fp) >= (off_t)cfg->max_log_size) {
fclose(*fp);
*fp = NULL;
}
return result;
}
void fcloselog(FILE* fp)
......
......@@ -37,7 +37,7 @@ BOOL fmutex(const char* fname, const char* text, long max_age);
BOOL fcompare(const char* fn1, const char* fn2);
BOOL backup(const char* org, int backup_level, BOOL ren);
FILE* fopenlog(scfg_t*, const char* path);
size_t fwritelog(void* buf, size_t size, FILE*);
size_t fwritelog(scfg_t*, void* buf, size_t size, FILE**);
void fcloselog(FILE*);
#ifdef __cplusplus
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment