From 7ee09b8196107ccdc16bd87431ae4007d9b73e8c Mon Sep 17 00:00:00 2001 From: Martin Schultz Date: Tue, 4 Apr 2017 13:35:56 +0200 Subject: [PATCH] use macro during console creation on windows --- OpenFlipper.cc | 56 ++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/OpenFlipper.cc b/OpenFlipper.cc index 4e52dd91..915c5fee 100644 --- a/OpenFlipper.cc +++ b/OpenFlipper.cc @@ -111,62 +111,42 @@ #ifdef WIN32 +#define CONNECT_CONSOLE \ + FILE* check = freopen("CONIN$", "r", stdin); \ + if (check) { \ + std::cerr << "Error reopening stdin" << std::endl; \ + } \ + check = freopen("CONOUT$", "w", stdout); \ + if (check) { \ + std::cerr << "Error reopening stdout" << std::endl; \ + } \ + check = freopen("CONOUT$", "w", stderr); \ + if (check) { \ + std::cerr << "Error reopening stderr" << std::endl; \ + } + void attachConsole() { //try to attach the console of the parent process if (AttachConsole(-1)) { //if the console was attached change stdinput and output - FILE* check = freopen("CONIN$", "r", stdin); - if (check) { - std::cerr << "Error reopening stdin" << std::endl; - } - check = freopen("CONOUT$", "w", stdout); - if (check) { - std::cerr << "Error reopening stdout" << std::endl; - } - check = freopen("CONOUT$", "w", stderr); - if (check) { - std::cerr << "Error reopening stderr" << std::endl; - } + CONNECT_CONSOLE } else { //create and attach a new console if needed #ifndef NDEBUG //always open a console in debug mode - AllocConsole(); + AllocConsole(); + CONNECT_CONSOLE - FILE* check = freopen("CONIN$", "r", stdin); - if (check) { - std::cerr << "Error reopening stdin" << std::endl; - } - check = freopen("CONOUT$", "w", stdout); - if (check) { - std::cerr << "Error reopening stdout" << std::endl; - } - check = freopen("CONOUT$", "w", stderr); - if (check) { - std::cerr << "Error reopening stderr" << std::endl; - } return; #endif if (OpenFlipper::Options::logToConsole()) { AllocConsole(); - - FILE* check = freopen("CONIN$", "r", stdin); - if (check) { - std::cerr << "Error reopening stdin" << std::endl; - } - check = freopen("CONOUT$", "w", stdout); - if (check) { - std::cerr << "Error reopening stdout" << std::endl; - } - check = freopen("CONOUT$", "w", stderr); - if (check) { - std::cerr << "Error reopening stderr" << std::endl; - } + CONNECT_CONSOLE } } } -- GitLab