diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index 33456dc16..6555a7d44 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -181,6 +181,7 @@ void wm_setapptitle(char *name); int32_t baselayer_init(); void makeasmwriteable(void); +void maybe_redirect_outputs(void); #ifdef EXTERNC } diff --git a/polymer/eduke32/build/src/baselayer.c b/polymer/eduke32/build/src/baselayer.c index 2fb51958e..6f5b0eaed 100644 --- a/polymer/eduke32/build/src/baselayer.c +++ b/polymer/eduke32/build/src/baselayer.c @@ -476,3 +476,27 @@ void makeasmwriteable(void) # endif #endif } + +void maybe_redirect_outputs(void) +{ +#if !(defined __APPLE__ && defined __BIG_ENDIAN__) + char *argp; + + // pipe standard outputs to files + if ((argp = Bgetenv("BUILD_LOGSTDOUT")) != NULL) + if (!Bstrcasecmp(argp, "TRUE")) + { + FILE *fp = freopen("stdout.txt", "w", stdout); + + if (!fp) + fp = fopen("stdout.txt", "w"); + + if (fp) + { + setvbuf(fp, 0, _IONBF, 0); + *stdout = *fp; + *stderr = *fp; + } + } +#endif +} diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 25a8a146e..dcf9c348a 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -206,7 +206,6 @@ int32_t main(int32_t argc, char *argv[]) { int32_t r; char *argp; - FILE *fp; buildkeytranslationtable(); @@ -229,24 +228,7 @@ int32_t main(int32_t argc, char *argv[]) _buildargc = argc; _buildargv = (const char **)argv; -#if !(defined __APPLE__ && defined __BIG_ENDIAN__) - // pipe standard outputs to files - if ((argp = Bgetenv("BUILD_LOGSTDOUT")) != NULL) - if (!Bstrcasecmp(argp, "TRUE")) - { - fp = freopen("stdout.txt", "w", stdout); - - if (!fp) - fp = fopen("stdout.txt", "w"); - - if (fp) - { - setvbuf(fp, 0, _IONBF, 0); - *stdout = *fp; - *stderr = *fp; - } - } -#endif + maybe_redirect_outputs(); #ifdef USE_OPENGL if ((argp = Bgetenv("BUILD_NOFOG")) != NULL) diff --git a/polymer/eduke32/build/src/winlayer.c b/polymer/eduke32/build/src/winlayer.c index e1f8fe727..43d20fb01 100644 --- a/polymer/eduke32/build/src/winlayer.c +++ b/polymer/eduke32/build/src/winlayer.c @@ -316,7 +316,6 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in { int32_t r; char *argp; - FILE *fp; HDC hdc; UNREFERENCED_PARAMETER(lpCmdLine); @@ -419,19 +418,7 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in } } - // pipe standard outputs to files - if ((argp = Bgetenv("BUILD_LOGSTDOUT")) != NULL) - if (!Bstrcasecmp(argp, "TRUE")) - { - fp = freopen("stdout.txt", "w", stdout); - if (!fp) - { - fp = fopen("stdout.txt", "w"); - } - if (fp) setvbuf(fp, 0, _IONBF, 0); - *stdout = *fp; - *stderr = *fp; - } + maybe_redirect_outputs(); #ifdef USE_OPENGL if ((argp = Bgetenv("BUILD_NOFOG")) != NULL)