55{
56#if defined(_WIN32)
57 m_handle = {CreateFile(
file.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr)};
59 {
60 Term::Private::WindowsError().check_if((
m_handle = CreateFile(
"NUL", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr)) == INVALID_HANDLE_VALUE).throw_exception(
"Problem opening NUL");
62 }
63 Term::Private::Errno().check_if((
m_fd = _open_osfhandle(
reinterpret_cast<intptr_t
>(
m_handle), _O_RDWR)) == -1).throw_exception(
"_open_osfhandle(reinterpret_cast<intptr_t>(m_handle), _O_RDWR)");
64 Term::Private::Errno().check_if(
nullptr == (
m_file = _fdopen(
m_fd, mode.c_str()))).throw_exception(
"_fdopen(m_fd, mode.c_str())");
65#else
66 std::size_t flag{O_ASYNC | O_DSYNC | O_NOCTTY | O_SYNC | O_NDELAY};
67 flag &= ~static_cast<std::size_t>(O_NONBLOCK);
68 if(mode.find('r') != std::string::npos) { flag |= O_RDONLY; }
69 else if(mode.find('w') != std::string::npos) { flag |= O_WRONLY; }
70 else { flag |= O_RDWR; }
71 m_fd = {::open(
file.c_str(),
static_cast<int>(flag))};
73 {
74 Term::Private::Errno().check_if((
m_fd = ::open(
"/dev/null",
static_cast<int>(flag))) == -1).throw_exception(R
"(::open("/dev/null", flag))");
76 }
77 Term::Private::Errno().check_if(
nullptr == (
m_file = ::fdopen(
m_fd, mode.c_str()))).throw_exception(
"::fdopen(m_fd, mode.c_str())");
79#endif
80 Term::Private::Errno().check_if(std::setvbuf(
m_file,
nullptr, _IONBF, 0) != 0).throw_exception(
"std::setvbuf(m_file, nullptr, _IONBF, 0)");
81}
82catch(...)
83{
85}
std::recursive_mutex & m_mutex
std::FILE * file() const noexcept
void ExceptionHandler(const ExceptionDestination &destination=ExceptionDestination::StdErr) noexcept