From a318b203bea956dbe17c30f87c0a8a5293f027f2 Mon Sep 17 00:00:00 2001 From: m-holger Date: Thu, 25 Aug 2022 14:05:36 +0100 Subject: Refactor FileInputSource::seek and FileInputSource::unreadCh Avoid building error message each call "just in case". --- libqpdf/FileInputSource.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'libqpdf/FileInputSource.cc') diff --git a/libqpdf/FileInputSource.cc b/libqpdf/FileInputSource.cc index 1a0c2653..2c610801 100644 --- a/libqpdf/FileInputSource.cc +++ b/libqpdf/FileInputSource.cc @@ -102,11 +102,12 @@ FileInputSource::tell() void FileInputSource::seek(qpdf_offset_t offset, int whence) { - QUtil::os_wrapper( - (std::string("seek to ") + this->filename + ", offset " + - QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) + - ")"), - QUtil::seek(this->file, offset, whence)); + if (QUtil::seek(this->file, offset, whence) == -1) { + QUtil::throw_system_error( + std::string("seek to ") + this->filename + ", offset " + + QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) + + ")"); + } } void @@ -140,7 +141,7 @@ FileInputSource::read(char* buffer, size_t length) void FileInputSource::unreadCh(char ch) { - QUtil::os_wrapper( - this->filename + ": unread character", - ungetc(static_cast(ch), this->file)); + if (ungetc(static_cast(ch), this->file) == -1) { + QUtil::throw_system_error(this->filename + ": unread character"); + } } -- cgit v1.2.3-54-g00ecf