Commit a318b203bea956dbe17c30f87c0a8a5293f027f2
1 parent
dc5c8b82
Refactor FileInputSource::seek and FileInputSource::unreadCh
Avoid building error message each call "just in case".
Showing
1 changed file
with
9 additions
and
8 deletions
libqpdf/FileInputSource.cc
| @@ -102,11 +102,12 @@ FileInputSource::tell() | @@ -102,11 +102,12 @@ FileInputSource::tell() | ||
| 102 | void | 102 | void |
| 103 | FileInputSource::seek(qpdf_offset_t offset, int whence) | 103 | FileInputSource::seek(qpdf_offset_t offset, int whence) |
| 104 | { | 104 | { |
| 105 | - QUtil::os_wrapper( | ||
| 106 | - (std::string("seek to ") + this->filename + ", offset " + | ||
| 107 | - QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) + | ||
| 108 | - ")"), | ||
| 109 | - QUtil::seek(this->file, offset, whence)); | 105 | + if (QUtil::seek(this->file, offset, whence) == -1) { |
| 106 | + QUtil::throw_system_error( | ||
| 107 | + std::string("seek to ") + this->filename + ", offset " + | ||
| 108 | + QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) + | ||
| 109 | + ")"); | ||
| 110 | + } | ||
| 110 | } | 111 | } |
| 111 | 112 | ||
| 112 | void | 113 | void |
| @@ -140,7 +141,7 @@ FileInputSource::read(char* buffer, size_t length) | @@ -140,7 +141,7 @@ FileInputSource::read(char* buffer, size_t length) | ||
| 140 | void | 141 | void |
| 141 | FileInputSource::unreadCh(char ch) | 142 | FileInputSource::unreadCh(char ch) |
| 142 | { | 143 | { |
| 143 | - QUtil::os_wrapper( | ||
| 144 | - this->filename + ": unread character", | ||
| 145 | - ungetc(static_cast<unsigned char>(ch), this->file)); | 144 | + if (ungetc(static_cast<unsigned char>(ch), this->file) == -1) { |
| 145 | + QUtil::throw_system_error(this->filename + ": unread character"); | ||
| 146 | + } | ||
| 146 | } | 147 | } |