From ce9d743824be796471bae9b57c0185ef8ec1b804 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 8 Nov 2016 15:23:13 +0300 Subject: Add auto_fd::close() --- butl/fdstream | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'butl/fdstream') diff --git a/butl/fdstream b/butl/fdstream index 9c7274d..289d925 100644 --- a/butl/fdstream +++ b/butl/fdstream @@ -19,8 +19,7 @@ namespace butl { // RAII type for file descriptors. Note that failure to close the descriptor - // is silently ignored by both the destructor and reset() (thought we could - // probably provide the close() function that throws). + // is silently ignored by both the destructor and reset(). // // The descriptor can be negative. Such a descriptor is treated as unopened // and is not closed. @@ -28,7 +27,7 @@ namespace butl struct nullfd_t {constexpr explicit nullfd_t (int) {}}; constexpr const nullfd_t nullfd (-1); - class auto_fd + class LIBBUTL_EXPORT auto_fd { public: auto_fd (nullfd_t = nullfd): fd_ (-1) {} @@ -53,6 +52,12 @@ namespace butl void reset (int fd = -1) noexcept; + // Close an open file descriptor. Throw ios::failure on failure. The object + // become unopened whenever the exception is thrown or not. + // + void + close (); + private: int fd_; }; -- cgit v1.1