20 #pragma warning(disable : 4668)
21 #define WIN32_LEAN_AND_MEAN
24 #if defined(MessageBox)
41 bool need_allocation{
false};
44 case ERROR_SUCCESS:
break;
45 case ERROR_ACCESS_DENIED: need_allocation =
false;
break;
46 case ERROR_INVALID_PARAMETER: error.
throw_exception(
"The specified process does not exist !");
break;
47 case ERROR_INVALID_HANDLE: need_allocation =
true;
break;
78 static std::recursive_mutex ioMutex;
82 openStandardStreams();
113 FILE* fDummy{
nullptr};
114 if(_fileno(stderr) < 0 || _get_osfhandle(_fileno(stderr)) < 0) {
Term::Private::Errno().
check_if(_wfreopen_s(&fDummy, L
"CONOUT$", L
"w", stderr) != 0).
throw_exception(R
"(_wfreopen_s(&fDummy, L"CONOUT$", L"w", stderr))"); }
115 if(_fileno(stdout) < 0 || _get_osfhandle(_fileno(stdout)) < 0) {
Term::Private::Errno().
check_if(_wfreopen_s(&fDummy, L
"CONOUT$", L
"w", stdout) != 0).
throw_exception(R
"(_wfreopen_s(&fDummy, L"CONOUT$", L"w", stdout))"); }
116 if(_fileno(stdin) < 0 || _get_osfhandle(_fileno(stdin)) < 0) {
Term::Private::Errno().
check_if(_wfreopen_s(&fDummy, L
"CONIN$", L
"r", stdin) != 0).
throw_exception(R
"(_wfreopen_s(&fDummy, L"CONIN$", L"r", stdin))"); }
117 const std::size_t bestSize{BUFSIZ > 4096 ? BUFSIZ : 4096};
122 struct stat stats = {};
123 ::stat(
"/dev/tty", &stats);
124 const std::size_t bestSize{
static_cast<std::size_t
>(stats.st_blksize) > 0 ?
static_cast<std::size_t
>(stats.st_blksize) : BUFSIZ};
void throw_exception(const std::string &str={}) const
Errno & check_if(const bool &ret) noexcept
FileInitializer() noexcept
static void attachConsole() noexcept
Attach the console.
~FileInitializer() noexcept
static void openStandardStreams() noexcept
Open the standard streams.
static bool m_consoleCreated
static std::size_t m_counter
static void detachConsole() noexcept
Detach the console.
WindowsError & check_if(const bool &ret) noexcept
void throw_exception(const std::string &str=std::string()) const
void ExceptionHandler(const ExceptionDestination &destination=ExceptionDestination::StdErr) noexcept