Factor "pipe standard outputs to files" code into baselayer.c.

The SDL and Windows layers had slightly different code: the latter would
dereference a NULL pointer if stdout.txt failed being write-opened.

git-svn-id: https://svn.eduke32.com/eduke32@3377 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-01-06 18:56:29 +00:00
parent 1e91bf1800
commit a959b998bd
4 changed files with 27 additions and 33 deletions

View file

@ -181,6 +181,7 @@ void wm_setapptitle(char *name);
int32_t baselayer_init();
void makeasmwriteable(void);
void maybe_redirect_outputs(void);
#ifdef EXTERNC
}

View file

@ -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
}

View file

@ -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)

View file

@ -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)