From 8283f23651580c57e199f7547f2c0a0512e868be Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 11 Aug 2014 22:53:48 +0200 Subject: [PATCH] fs/io/TextFile: add method Check() --- src/fs/io/TextFile.cxx | 8 ++++++++ src/fs/io/TextFile.hxx | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/fs/io/TextFile.cxx b/src/fs/io/TextFile.cxx index 5b3bc4505..28d6dabcb 100644 --- a/src/fs/io/TextFile.cxx +++ b/src/fs/io/TextFile.cxx @@ -61,3 +61,11 @@ TextFile::ReadLine() return buffered_reader->ReadLine(); } + +bool +TextFile::Check(Error &error) const +{ + assert(buffered_reader != nullptr); + + return buffered_reader->Check(error); +} diff --git a/src/fs/io/TextFile.hxx b/src/fs/io/TextFile.hxx index 8bab808c7..5577363e7 100644 --- a/src/fs/io/TextFile.hxx +++ b/src/fs/io/TextFile.hxx @@ -56,10 +56,18 @@ public: * space. There is a reasonable maximum line length, only to * prevent denial of service. * + * Use Check() after nullptr has been returned to check + * whether an error occurred or end-of-file has been reached. + * * @param file the source file, opened in text mode * @return a pointer to the line, or nullptr on end-of-file or error */ char *ReadLine(); + + /** + * Check whether a ReadLine() call has thrown an error. + */ + bool Check(Error &error) const; }; #endif