88 std::string buff(80,
'\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 buff.resize(buff.find(
'\0'));
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) +
213 mode |= std::ios_base::in;
214 exceptions(std::ios_base::badbit);
216 std::ifstream::open(filename, mode);
223 mode |= std::ios_base::out;
224 exceptions(std::ios_base::badbit);
226 std::ofstream::open(filename, mode);
232 if (! (mode & std::ios_base::out)) {
233 mode |= std::ios_base::in;
235 exceptions(std::ios_base::badbit);
237 std::fstream::open(filename, mode);
static std::string mode_to_string_(std::ios_base::openmode mode)
Exception class for general input/output errors.
static void check_open_(std::ios *s_p, std::string const &filename, std::ios_base::openmode mode)
void open(std::string const &filename, std::ios_base::openmode mode=std::ios_base::in)
void swap(SequenceSet &lhs, SequenceSet &rhs)
static void check_peek_(std::istream *is_p, std::string const &filename, std::ios_base::openmode mode)
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
static void check_mode_(std::string const &filename, std::ios_base::openmode mode)
void open(std::string const &filename, std::ios_base::openmode mode=std::ios_base::in)
void open(std::string const &filename, std::ios_base::openmode mode=std::ios_base::out)
static std::string strerror_()
Overload of error-reporting function, to enable use with VS.