X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESHUtils%2FSMESH_File.cxx;h=d4311bb71ef29464b7b926b689e2f1bbbc5dfa61;hb=13ff035dac9cce5567d2f3d34d6fbaabafa46492;hp=ae5f9bb111868ced9102a16a34266df3b9bdf133;hpb=e09cefb492091eed2987a366e9d607d0078e8cb9;p=modules%2Fsmesh.git diff --git a/src/SMESHUtils/SMESH_File.cxx b/src/SMESHUtils/SMESH_File.cxx index ae5f9bb11..d4311bb71 100644 --- a/src/SMESHUtils/SMESH_File.cxx +++ b/src/SMESHUtils/SMESH_File.cxx @@ -21,8 +21,8 @@ // Created : Wed Mar 10 11:23:25 2010 // Author : Edward AGAPOV (eap) // + #include "SMESH_File.hxx" -#include "utilities.h" #include #include @@ -45,7 +45,13 @@ namespace boofs = boost::filesystem; //================================================================================ SMESH_File::SMESH_File(const std::string& name, bool open) - :_name(name), _size(-1), _file(0), _map(0), _pos(0), _end(0) + :_name(name), _size(-1), +#ifdef WIN32 + _file(INVALID_HANDLE_VALUE), +#else + _file(-1), +#endif + _map(0), _pos(0), _end(0) { if ( open ) this->open(); } @@ -78,7 +84,7 @@ bool SMESH_File::open() bool ok = ( _file != INVALID_HANDLE_VALUE ); #else _file = ::open(_name.data(), O_RDONLY ); - bool ok = ( _file > 0 ); + bool ok = ( _file >= 0 ); #endif if ( ok ) { @@ -105,6 +111,10 @@ bool SMESH_File::open() #endif } } + else if ( _error.empty() ) + { + _error = "Can't open for reading an existing file " + _name; + } } return _pos; } @@ -134,11 +144,15 @@ void SMESH_File::close() else if ( _file >= 0 ) { #ifdef WIN32 - CloseHandle(_file); - _file = INVALID_HANDLE_VALUE; + if(_file != INVALID_HANDLE_VALUE) { + CloseHandle(_file); + _file = INVALID_HANDLE_VALUE; + } #else - ::close(_file); - _file = -1; + if(_file != -1) { + ::close(_file); + _file = -1; + } #endif } } @@ -171,7 +185,7 @@ long SMESH_File::size() if ( _size >= 0 ) return _size; // size of an open file boost::system::error_code err; - uintmax_t size = boofs::file_size( _name, err ); + boost::uintmax_t size = boofs::file_size( _name, err ); _error = err.message(); return err ? -1 : (long) size;