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 ) {
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 ) {
151 bool OFile::flush() {
155 int result = fflush(file);
Embedded control libraries.
WriteMode
Write mode for devices.
#define ecl_throw(exception)
StandardException open_exception(const char *loc, const std::string &file_name)
StandardException close_exception(const char *loc, const std::string &file_name)
#define ecl_debug_throw(exception)
#define ecl_catch(exception)
Opens a new object (deletes existing objects).
Appends to an existing object (opens if not existing).