From c36042925c8d52e3899ea310018cb7243d191306 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 23 Jun 2017 14:14:16 +0200 Subject: Add support for querying position in fdbuf --- libbutl/fdstream.hxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'libbutl/fdstream.hxx') diff --git a/libbutl/fdstream.hxx b/libbutl/fdstream.hxx index 771d242..27530e2 100644 --- a/libbutl/fdstream.hxx +++ b/libbutl/fdstream.hxx @@ -10,7 +10,7 @@ #include #include #include // move() -#include // uint16_t +#include // uint16_t, uint64_t #include @@ -143,6 +143,11 @@ namespace butl using base::egptr; using base::gbump; + // Return the (logical) position of the next byte to be read. + // + uint64_t + tellg () const {return off_ - (egptr () - gptr ());} + private: bool load (); @@ -159,12 +164,18 @@ namespace butl virtual std::streamsize xsputn (const char_type*, std::streamsize); + // Return the (logical) position of the next byte to be written. + // + uint64_t + tellp () const {return off_ + (pptr () - buf_);} + private: bool save (); private: auto_fd fd_; + uint64_t off_; char buf_[8192]; bool non_blocking_ = false; }; -- cgit v1.1