From 2acc4f075932e711cfacd198672f7c99ea4b853e Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Fri, 5 Sep 2003 18:04:52 +0000 Subject: [PATCH] Added log file maximum size support --- src/log.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index 282898c..144eb3b 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,14 +1,18 @@ // // Log handler // -// by cal2 +// by Cal2 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) // Cleanups/new stuff by James L. Hammons // +#include "types.h" #include "log.h" -FILE * log_stream = NULL; +#define MAX_LOG_SIZE 10000000 // Maximum size of log file (10 MB) + +static FILE * log_stream = NULL; +static uint32 logSize = 0; int log_init(char * path) { @@ -39,7 +43,15 @@ void WriteLog(const char * text, ...) va_list arg; va_start(arg, text); - vfprintf(log_stream, text, arg); + logSize += vfprintf(log_stream, text, arg); + + if (logSize > MAX_LOG_SIZE) + { + fflush(log_stream); + fclose(log_stream); + exit(1); + } + va_end(arg); fflush(log_stream); // Make sure that text is written! } -- 2.37.2