From a318b203bea956dbe17c30f87c0a8a5293f027f2 Mon Sep 17 00:00:00 2001 From: m-holger Date: Thu, 25 Aug 2022 14:05:36 +0100 Subject: [PATCH] Refactor FileInputSource::seek and FileInputSource::unreadCh --- libqpdf/FileInputSource.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libqpdf/FileInputSource.cc b/libqpdf/FileInputSource.cc index 1a0c265..2c61080 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"); + } } -- libgit2 0.21.4