diff --git a/fdstream.cpp b/fdstream.cpp index b977e34..ae1c30b 100644 --- a/fdstream.cpp +++ b/fdstream.cpp @@ -10,18 +10,30 @@ #include sc::io::fdostream::~fdostream() { + close(); +} + +void sc::io::fdostream::close() { if (_outbuf.fd() != -1) { ::close(_outbuf.fd()); } } sc::io::fdistream::~fdistream() { + close(); +} + +void sc::io::fdistream::close() { if (_inbuf.fd() != -1) { ::close(_inbuf.fd()); } } sc::io::fdstream::~fdstream() { + close(); +} + +void sc::io::fdstream::close() { if (_iobuf.fd() != -1) { ::close(_iobuf.fd()); } diff --git a/libscio.hpp b/libscio.hpp index 051e0ce..05ed456 100644 --- a/libscio.hpp +++ b/libscio.hpp @@ -61,6 +61,9 @@ namespace sc { int fd() const { return _outbuf.fd(); } void fd(int fd) { _outbuf.fd(fd); } + bool is_open() const { return _outbuf.fd() != -1; } + void close(); + protected: fdiobuf _outbuf; }; @@ -75,6 +78,9 @@ namespace sc { int fd() const { return _inbuf.fd(); } void fd(int fd) { _inbuf.fd(fd); } + bool is_open() const { return _inbuf.fd() != -1; } + void close(); + protected: fdiobuf _inbuf; }; @@ -89,6 +95,9 @@ namespace sc { int fd() const { return _iobuf.fd(); } void fd(int fd) { _iobuf.fd(fd); } + bool is_open() const { return _iobuf.fd() != -1; } + void close(); + protected: fdiobuf _iobuf {-1}; };