Skip to content

Commit

Permalink
Fix logic in porting::attachOrCreateConsole()
Browse files Browse the repository at this point in the history
No functional change but now the comment is actually correct.
  • Loading branch information
sfan5 committed Jan 6, 2024
1 parent e04f618 commit 6550bc2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/porting.cpp
Expand Up @@ -737,12 +737,14 @@ void osSpecificInit()
void attachOrCreateConsole()
{
#ifdef _WIN32
static bool consoleAllocated = false;
const bool redirected = (_fileno(stdout) == -2 || _fileno(stdout) == -1); // If output is redirected to e.g a file
if (!consoleAllocated && redirected && (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())) {
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
consoleAllocated = true;
static bool once = false;
const bool redirected = _fileno(stdout) >= 0; // If output is redirected to e.g a file
if (!once && !redirected) {
if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole()) {
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
once = true;
}
#endif
}
Expand Down

0 comments on commit 6550bc2

Please sign in to comment.