diff --git a/sc2/src/port.h b/sc2/src/port.h index 07475e2f0..f5ee575df 100644 --- a/sc2/src/port.h +++ b/sc2/src/port.h @@ -498,5 +498,19 @@ typedef unsigned int wint_t; # define _NORETURN #endif +// Buffered vs. unbuffered logfile +// stderr is normally unbuffered when connected to a terminal, but it +// will be buffered when connected to a file, when a --logfile argument +// is passed to uqm. +// Buffered output is slower, which can be significant if much debug output +// is requested, but after a crash occurs the logfile will still be up to +// date. +// On platforms where there is no console, having up-to-date log files +// after a crash is valuable enough to make the logfile unbuffered by +// default there. +#if defined(_WIN32_WCE) +# define UNBUFFERED_LOGFILE +#endif + #endif /* _PORT_H */ diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index dd04e98b9..35ef17e3f 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -154,6 +154,9 @@ main (int argc, char *argv[]) { int i; freopen (options.logFile, "w", stderr); +#ifdef UNBUFFERED_LOGFILE + setbuf (stderr, NULL); +#endif for (i = 0; i < argc; ++i) log_add (log_User, "argv[%d] = [%s]", i, argv[i]); }