13 #include <ecl/config/ecl.hpp>
14 #if defined(ECL_IS_WIN32)
20 #include "../../include/ecl/devices/ofile_w32.hpp"
21 #include "../../include/ecl/devices/detail/error_handler.hpp"
41 OFile::OFile(
const std::string &file_name,
const WriteMode &write_mode) :
46 open(file_name,write_mode);
55 if ( fclose(file) != 0 ) {
66 bool OFile::open(
const std::string &file_name,
const WriteMode &write_mode) {
70 if (_sopen_s(&file_descriptor, name.c_str(), _O_WRONLY | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE)) {
75 file = _fdopen(file_descriptor,
"w");
79 if (_sopen_s(&file_descriptor, name.c_str(), _O_WRONLY | _O_APPEND | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE)) {
84 file = _fdopen(file_descriptor,
"a");
101 if ( fclose(file) != 0 ) {
115 long OFile::write(
const char &c)
118 ecl_debug_throw(StandardException(LOC, OpenError, std::string(
"File ") + name + std::string(
" is not open for writing.")));
122 size_t written = fwrite(&c,1,1,file);
123 if ( written <= 0 ) {
124 ecl_debug_throw(StandardException(LOC, WriteError, std::string(
"Could not write to ") + name + std::string(
".")));
133 long OFile::write(
const char* s,
unsigned long n)
136 ecl_debug_throw(StandardException(LOC, OpenError, std::string(
"File ") + name + std::string(
" is not open for writing.")));
140 size_t written = fwrite(s,n,1,file);
141 if ( written <= 0 ) {
142 ecl_debug_throw(StandardException(LOC, WriteError, std::string(
"Could not write to ") + name + std::string(
".")));
151 bool OFile::flush() {
155 int result = fflush(file);
157 ecl_debug_throw ( StandardException(LOC, UnknownError, std::string(
"Could not fflush ") + name + std::string(
".")));