From bc1c4bb57864c4dbe9b7e42a77e0653c0d473071 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 21 Jun 2012 07:59:56 -0400 Subject: Add QPDF::processFile that takes an open FILE* --- libqpdf/QPDF.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'libqpdf/QPDF.cc') diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 7ed00c98..1c47d893 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -80,6 +80,7 @@ QPDF::InputSource::readLine() } QPDF::FileInputSource::FileInputSource() : + close_file(false), file(0) { } @@ -89,10 +90,21 @@ QPDF::FileInputSource::setFilename(char const* filename) { destroy(); this->filename = filename; + this->close_file = true; this->file = QUtil::fopen_wrapper(std::string("open ") + this->filename, fopen(this->filename.c_str(), "rb")); } +void +QPDF::FileInputSource::setFile(FILE* f) +{ + destroy(); + this->filename = "stdio FILE"; + this->close_file = false; + this->file = f; + this->seek(0, SEEK_SET); +} + QPDF::FileInputSource::~FileInputSource() { destroy(); @@ -101,7 +113,7 @@ QPDF::FileInputSource::~FileInputSource() void QPDF::FileInputSource::destroy() { - if (this->file) + if (this->file && this->close_file) { fclose(this->file); this->file = 0; @@ -316,6 +328,15 @@ QPDF::processFile(char const* filename, char const* password) parse(password); } +void +QPDF::processFile(FILE* filep, char const* password) +{ + FileInputSource* fi = new FileInputSource(); + this->file = fi; + fi->setFile(filep); + parse(password); +} + void QPDF::processMemoryFile(char const* description, char const* buf, size_t length, -- cgit v1.2.3-54-g00ecf