From 85f7a22e64bcfc0cdb57709f00b90bee27ea6f60 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Wed, 25 Mar 2015 02:56:49 +0100 Subject: [PATCH] flush logfile in case of crash --- source/src/main.cpp | 3 ++- source/src/stream.cpp | 1 + source/src/tools.h | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/src/main.cpp b/source/src/main.cpp index ac3cf10e..d73a9bad 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -4,6 +4,7 @@ void cleanup(char *msg) // single program exit point; { + if(clientlogfile) clientlogfile->fflush(); if(!msg) { cleanupclient(); @@ -29,6 +30,7 @@ VAR(resetcfg, 0, 0, 1); void quit() // normal exit { + if(clientlogfile) clientlogfile->fflush(); const char *onquit = getalias("onQuit"); if(onquit && onquit[0]) execute(onquit); alias("onQuit", ""); @@ -43,7 +45,6 @@ void quit() // normal exit writeallxmaps(); cleanup(NULL); popscontext(); - extern stream *clientlogfile; DELETEP(clientlogfile); exit(EXIT_SUCCESS); } diff --git a/source/src/stream.cpp b/source/src/stream.cpp index 363efc53..9df6bff6 100644 --- a/source/src/stream.cpp +++ b/source/src/stream.cpp @@ -422,6 +422,7 @@ struct filestream : stream bool end() { return feof(file)!=0; } long tell() { return ftell(file); } bool seek(long offset, int whence) { return fseek(file, offset, whence) >= 0; } + void fflush() { if(file) ::fflush(file); } int read(void *buf, int len) { return (int)fread(buf, 1, len, file); } int write(const void *buf, int len) { return (int)fwrite(buf, 1, len, file); } int getchar() { return fgetc(file); } diff --git a/source/src/tools.h b/source/src/tools.h index e8a61901..be825d31 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -14,9 +14,9 @@ typedef unsigned int uint; #ifdef _DEBUG #ifdef __GNUC__ -#define ASSERT(c) if(!(c)) { asm("int $3"); } +#define ASSERT(c) if(!(c)) { fflush(NULL); asm("int $3"); } #else -#define ASSERT(c) if(!(c)) { __asm int 3 } +#define ASSERT(c) if(!(c)) { fflush(NULL); { __asm int 3 } } #endif #include @@ -914,6 +914,7 @@ struct stream virtual long tell() { return -1; } virtual bool seek(long offset, int whence = SEEK_SET) { return false; } virtual long size(); + virtual void fflush() {} virtual int read(void *buf, int len) { return 0; } virtual int write(const void *buf, int len) { return 0; } virtual int getchar() { uchar c; return read(&c, 1) == 1 ? c : -1; }