88 std::string buff(512,
'\0');
92 if( strerror_s( &buff[0], buff.size(), errno ) != 0 ) {
93 buff =
"Unknown error";
96 #elif ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE) || defined(__APPLE__)
99 if( strerror_r( errno, &buff[0], buff.size() ) != 0 ) {
100 buff =
"Unknown error";
106 auto p = strerror_r(errno, &buff[0], buff.size());
107 std::string tmp(p, std::strlen( p ));
112 return std::string( buff.c_str() );
121 static const int n_modes = 6;
122 static const std::ios_base::openmode mode_val_v[n_modes] =
128 std::ios_base::trunc,
129 std::ios_base::binary
132 static char const* mode_name_v[n_modes] =
143 for (
int i = 0; i < n_modes; ++i) {
144 if (mode & mode_val_v[i]) {
145 res += (! res.empty()?
"|" :
"");
146 res += mode_name_v[i];
156 static void check_mode_( std::string
const& filename, std::ios_base::openmode mode )
158 if ((mode & std::ios_base::trunc) && ! (mode & std::ios_base::out)) {
160 std::string(
"Strict IO File Stream: open('") + filename +
"'): mode error: trunc and not out",
163 }
else if ((mode & std::ios_base::app) && ! (mode & std::ios_base::out)) {
165 std::string(
"Strict IO File Stream: open('") + filename +
"'): mode error: app and not out",
168 }
else if ((mode & std::ios_base::trunc) && (mode & std::ios_base::app)) {
170 std::string(
"Strict IO File Stream: open('") + filename +
"'): mode error: trunc and app",
176 static void check_open_(std::ios * s_p, std::string
const& filename, std::ios_base::openmode mode )
180 std::string(
"Strict IO File Stream: open('") + filename +
"'," +
mode_to_string_(mode) +
187 static void check_peek_(std::istream * is_p, std::string
const& filename, std::ios_base::openmode mode )
189 bool peek_failed =
true;
192 peek_failed = is_p->fail();
193 }
catch( std::ios_base::failure
const& e ) {
198 std::string(
"Strict IO File Stream: open('") + filename +
"'," +
mode_to_string_(mode) +
212 mode |= std::ios_base::in;
213 exceptions(std::ios_base::badbit);
215 std::ifstream::open(filename, mode);
222 mode |= std::ios_base::out;
223 exceptions(std::ios_base::badbit);
225 std::ofstream::open(filename, mode);
231 if (! (mode & std::ios_base::out)) {
232 mode |= std::ios_base::in;
234 exceptions(std::ios_base::badbit);
236 std::fstream::open(filename, mode);