#include <cpp-terminal/private/file_initializer.hpp>
Definition at line 20 of file file_initializer.hpp.
◆ ~FileInitializer()
Term::Private::FileInitializer::~FileInitializer |
( |
| ) |
|
|
noexcept |
Definition at line 93 of file file_initializer.cpp.
95{
98 {
102 }
103}
104catch(...)
105{
107}
static std::size_t m_counter
static void detachConsole() noexcept
Detach the console.
void ExceptionHandler(const ExceptionDestination &destination=ExceptionDestination::StdErr) noexcept
◆ FileInitializer() [1/3]
Term::Private::FileInitializer::FileInitializer |
( |
| ) |
|
|
noexcept |
Definition at line 74 of file file_initializer.cpp.
76{
77
78 static std::recursive_mutex ioMutex;
80 {
85 }
87}
88catch(...)
89{
91}
static void attachConsole() noexcept
Attach the console.
static void openStandardStreams() noexcept
Open the standard streams.
◆ FileInitializer() [2/3]
◆ FileInitializer() [3/3]
Term::Private::FileInitializer::FileInitializer |
( |
const FileInitializer & | | ) |
|
|
delete |
◆ attachConsole()
void Term::Private::FileInitializer::attachConsole |
( |
| ) |
|
|
staticprivatenoexcept |
Attach the console.
Check if a console is attached to the process. If not, try to attach to the console. If there is no console, then create one.
Definition at line 35 of file file_initializer.cpp.
37{
38#if defined(_WIN32)
39
41 bool need_allocation{false};
42 switch(error.error())
43 {
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;
48 }
49 if(need_allocation)
50 {
53 }
54#endif
55}
56catch(...)
57{
60}
static bool m_consoleCreated
WindowsError & check_if(const bool &ret) noexcept
void throw_exception(const std::string &str=std::string()) const
◆ detachConsole()
void Term::Private::FileInitializer::detachConsole |
( |
| ) |
|
|
staticprivatenoexcept |
Detach the console.
If a console as been created, then delete it.
Definition at line 62 of file file_initializer.cpp.
64{
65#if defined(_WIN32)
67#endif
68}
69catch(...)
70{
72}
◆ openStandardStreams()
void Term::Private::FileInitializer::openStandardStreams |
( |
| ) |
|
|
staticprivatenoexcept |
Open the standard streams.
Open stdout stderr stdin and adjust their buffer size and line discipline.
Definition at line 109 of file file_initializer.cpp.
111{
112#if defined(_WIN32)
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};
118#else
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};
125#endif
129}
130catch(...)
131{
133}
void throw_exception(const std::string &str={}) const
Errno & check_if(const bool &ret) noexcept
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ m_consoleCreated
bool Term::Private::FileInitializer::m_consoleCreated = {false} |
|
staticprivate |
◆ m_counter
std::size_t Term::Private::FileInitializer::m_counter = {0} |
|
staticprivate |
The documentation for this class was generated from the following files: