diff --git a/test/scan.h b/test/scan.h index d5831528..c48357fc 100644 --- a/test/scan.h +++ b/test/scan.h @@ -161,6 +161,17 @@ template class file_base { } }; +// A FILE wrapper for glibc. +template class glibc_file : public file_base { + public: + using file_base::file_base; + + auto buffer() const -> string_view { + return {this->file_->_IO_read_ptr, + to_unsigned(this->file_->_IO_read_end - this->file_->_IO_read_ptr)}; + } +}; + // A FILE wrapper for Apple's libc. template class apple_file : public file_base { public: @@ -196,6 +207,10 @@ template class fallback_file : public file_base { } }; +template +auto get_file(F* file, int) -> glibc_file { + return file; +} template auto get_file(F* file, int) -> apple_file { return file; @@ -206,7 +221,7 @@ class file_scan_buffer : public scan_buffer { private: decltype(get_file(static_cast(nullptr), 0)) file_; - void do_fill() { + void fill() { string_view buf = file_.buffer(); if (buf.size() == 0) { int c = file_.get(); @@ -220,14 +235,14 @@ class file_scan_buffer : public scan_buffer { void consume() override { // Consume the current buffer content. for (size_t i = 0, n = file_.buffer().size(); i != n; ++i) file_.get(); - do_fill(); + fill(); } public: explicit file_scan_buffer(FILE* f) : scan_buffer(nullptr, nullptr, false), file_(f) { // TODO: lock file? - do_fill(); + fill(); } }; } // namespace detail