diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/exception.hh | 8 | ||||
-rw-r--r-- | util/read_compressed.cc | 11 | ||||
-rw-r--r-- | util/read_compressed.hh | 4 |
3 files changed, 19 insertions, 4 deletions
diff --git a/util/exception.hh b/util/exception.hh index 2fb00667f..4e50a6f3a 100644 --- a/util/exception.hh +++ b/util/exception.hh @@ -1,5 +1,5 @@ -#ifndef UTIL_EXCEPTION__ -#define UTIL_EXCEPTION__ +#ifndef UTIL_EXCEPTION_H +#define UTIL_EXCEPTION_H #include <exception> #include <limits> @@ -84,7 +84,7 @@ template <class Except, class Data> typename Except::template ExceptionTag<Excep UTIL_THROW_BACKEND(NULL, Exception, , Modify); #define UTIL_THROW2(Modify) \ - UTIL_THROW_BACKEND(NULL, util::Exception, , Modify); + UTIL_THROW_BACKEND(NULL, util::Exception, , Modify); #if __GNUC__ >= 3 #define UTIL_UNLIKELY(x) __builtin_expect (!!(x), 0) @@ -146,4 +146,4 @@ inline std::size_t CheckOverflow(uint64_t value) { } // namespace util -#endif // UTIL_EXCEPTION__ +#endif // UTIL_EXCEPTION_H diff --git a/util/read_compressed.cc b/util/read_compressed.cc index 71ef0e251..e1f4cd7e3 100644 --- a/util/read_compressed.cc +++ b/util/read_compressed.cc @@ -435,4 +435,15 @@ std::size_t ReadCompressed::Read(void *to, std::size_t amount) { return internal_->Read(to, amount, *this); } +std::size_t ReadCompressed::ReadOrEOF(void *const to_in, std::size_t amount) { + uint8_t *to = reinterpret_cast<uint8_t*>(to_in); + while (amount) { + std::size_t got = Read(to, amount); + if (!got) break; + to += got; + amount -= got; + } + return to - reinterpret_cast<uint8_t*>(to_in); +} + } // namespace util diff --git a/util/read_compressed.hh b/util/read_compressed.hh index 763e6bbd3..767ee94b2 100644 --- a/util/read_compressed.hh +++ b/util/read_compressed.hh @@ -62,6 +62,10 @@ class ReadCompressed { std::size_t Read(void *to, std::size_t amount); + // Repeatedly call read to fill a buffer unless EOF is hit. + // Return number of bytes read. + std::size_t ReadOrEOF(void *const to, std::size_t amount); + uint64_t RawAmount() const { return raw_amount_; } private: |