Commit 4f305488d85f9237c561f04a88570f9b0584cb0d
1 parent
7f95ad5b
Improve the FILE* version of QPDF::processFile
Showing
3 changed files
with
15 additions
and
11 deletions
include/qpdf/QPDF.hh
| @@ -55,10 +55,12 @@ class QPDF | @@ -55,10 +55,12 @@ class QPDF | ||
| 55 | // Parse a PDF from a stdio FILE*. The FILE must be open in | 55 | // Parse a PDF from a stdio FILE*. The FILE must be open in |
| 56 | // binary mode and must be seekable. It may be open read only. | 56 | // binary mode and must be seekable. It may be open read only. |
| 57 | // This works exactly like processFile except that the PDF file is | 57 | // This works exactly like processFile except that the PDF file is |
| 58 | - // read from an already opened FILE*. The caller is responsible | ||
| 59 | - // for closing the file. | 58 | + // read from an already opened FILE*. If close_file is true, the |
| 59 | + // file will be closed at the end. Otherwise, the caller is | ||
| 60 | + // responsible for closing the file. | ||
| 60 | QPDF_DLL | 61 | QPDF_DLL |
| 61 | - void processFile(FILE* file, char const* password = 0); | 62 | + void processFile(char const* description, FILE* file, |
| 63 | + bool close_file, char const* password = 0); | ||
| 62 | 64 | ||
| 63 | // Parse a PDF file loaded into a memory buffer. This works | 65 | // Parse a PDF file loaded into a memory buffer. This works |
| 64 | // exactly like processFile except that the PDF file is in memory | 66 | // exactly like processFile except that the PDF file is in memory |
| @@ -449,7 +451,7 @@ class QPDF | @@ -449,7 +451,7 @@ class QPDF | ||
| 449 | public: | 451 | public: |
| 450 | FileInputSource(); | 452 | FileInputSource(); |
| 451 | void setFilename(char const* filename); | 453 | void setFilename(char const* filename); |
| 452 | - void setFile(FILE* filep); | 454 | + void setFile(char const* description, FILE* filep, bool close_file); |
| 453 | virtual ~FileInputSource(); | 455 | virtual ~FileInputSource(); |
| 454 | virtual std::string const& getName() const; | 456 | virtual std::string const& getName() const; |
| 455 | virtual qpdf_offset_t tell(); | 457 | virtual qpdf_offset_t tell(); |
libqpdf/QPDF.cc
| @@ -114,12 +114,13 @@ QPDF::FileInputSource::setFilename(char const* filename) | @@ -114,12 +114,13 @@ QPDF::FileInputSource::setFilename(char const* filename) | ||
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | void | 116 | void |
| 117 | -QPDF::FileInputSource::setFile(FILE* f) | 117 | +QPDF::FileInputSource::setFile( |
| 118 | + char const* description, FILE* filep, bool close_file) | ||
| 118 | { | 119 | { |
| 119 | destroy(); | 120 | destroy(); |
| 120 | - this->filename = "stdio FILE"; | ||
| 121 | - this->close_file = false; | ||
| 122 | - this->file = f; | 121 | + this->filename = description; |
| 122 | + this->close_file = close_file; | ||
| 123 | + this->file = filep; | ||
| 123 | this->seek(0, SEEK_SET); | 124 | this->seek(0, SEEK_SET); |
| 124 | } | 125 | } |
| 125 | 126 | ||
| @@ -347,11 +348,12 @@ QPDF::processFile(char const* filename, char const* password) | @@ -347,11 +348,12 @@ QPDF::processFile(char const* filename, char const* password) | ||
| 347 | } | 348 | } |
| 348 | 349 | ||
| 349 | void | 350 | void |
| 350 | -QPDF::processFile(FILE* filep, char const* password) | 351 | +QPDF::processFile(char const* description, FILE* filep, |
| 352 | + bool close_file, char const* password) | ||
| 351 | { | 353 | { |
| 352 | FileInputSource* fi = new FileInputSource(); | 354 | FileInputSource* fi = new FileInputSource(); |
| 353 | this->file = fi; | 355 | this->file = fi; |
| 354 | - fi->setFile(filep); | 356 | + fi->setFile(description, filep, close_file); |
| 355 | parse(password); | 357 | parse(password); |
| 356 | } | 358 | } |
| 357 | 359 |
qpdf/test_driver.cc
| @@ -104,7 +104,7 @@ void runtest(int n, char const* filename) | @@ -104,7 +104,7 @@ void runtest(int n, char const* filename) | ||
| 104 | QTC::TC("qpdf", "exercise processFile(FILE*)"); | 104 | QTC::TC("qpdf", "exercise processFile(FILE*)"); |
| 105 | filep = QUtil::fopen_wrapper(std::string("open ") + filename, | 105 | filep = QUtil::fopen_wrapper(std::string("open ") + filename, |
| 106 | fopen(filename, "rb")); | 106 | fopen(filename, "rb")); |
| 107 | - pdf.processFile(filep); | 107 | + pdf.processFile(filename, filep, false); |
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | else | 110 | else |