From af91b5b5841aaa34ebf2d2062041c874425f474f Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 29 Dec 2021 10:36:15 -0500 Subject: Add QUtil::file_can_be_opened --- libqpdf/QUtil.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libqpdf') diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index f45468a0..daa663a3 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -515,6 +515,21 @@ QUtil::fopen_wrapper(std::string const& description, FILE* f) return f; } +bool +QUtil::file_can_be_opened(char const* filename) +{ + try + { + fclose(safe_fopen(filename, "rb")); + return true; + } + catch (std::runtime_error&) + { + // can't open the file + } + return false; +} + int QUtil::seek(FILE* stream, qpdf_offset_t offset, int whence) { -- cgit v1.2.3-54-g00ecf