89 std::string buff(512,
'\0');
93 if( strerror_s( &buff[0], buff.size(), errno ) != 0 ) {
94 buff =
"Unknown error";
97 #elif ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE) || defined(__APPLE__)
100 if( strerror_r( errno, &buff[0], buff.size() ) != 0 ) {
101 buff =
"Unknown error";
107 auto p = strerror_r(errno, &buff[0], buff.size());
108 std::string tmp(p, std::strlen( p ));
113 return std::string( buff.c_str() );
122 static const int n_modes = 6;
123 static const std::ios_base::openmode mode_val_v[n_modes] =
129 std::ios_base::trunc,
130 std::ios_base::binary
133 static char const* mode_name_v[n_modes] =
144 for (
int i = 0; i < n_modes; ++i) {
145 if (mode & mode_val_v[i]) {
146 res += (! res.empty()?
"|" :
"");
147 res += mode_name_v[i];
157 static void check_mode_( std::string
const& filename, std::ios_base::openmode mode )
159 if ((mode & std::ios_base::trunc) && ! (mode & std::ios_base::out)) {
161 std::string(
"Strict IO File Stream: open('") + filename +
"'): mode error: trunc and not out",
164 }
else if ((mode & std::ios_base::app) && ! (mode & std::ios_base::out)) {
166 std::string(
"Strict IO File Stream: open('") + filename +
"'): mode error: app and not out",
169 }
else if ((mode & std::ios_base::trunc) && (mode & std::ios_base::app)) {
171 std::string(
"Strict IO File Stream: open('") + filename +
"'): mode error: trunc and app",
177 static void check_open_(std::ios * s_p, std::string
const& filename, std::ios_base::openmode mode )
181 std::string(
"Strict IO File Stream: open('") + filename +
"'," +
mode_to_string_(mode) +
188 static void check_peek_(std::istream * is_p, std::string
const& filename, std::ios_base::openmode mode )
190 bool peek_failed =
true;
193 peek_failed = is_p->fail();
194 }
catch( std::ios_base::failure
const& e ) {
199 std::string(
"Strict IO File Stream: open('") + filename +
"'," +
mode_to_string_(mode) +
214 mode |= std::ios_base::in;
215 exceptions(std::ios_base::badbit);
217 std::ifstream::open(filename, mode);
225 mode |= std::ios_base::out;
226 exceptions(std::ios_base::badbit);
228 std::ofstream::open(filename, mode);
235 if (! (mode & std::ios_base::out)) {
236 mode |= std::ios_base::in;
238 exceptions(std::ios_base::badbit);
240 std::fstream::open(filename, mode);