Commit 4f305488d85f9237c561f04a88570f9b0584cb0d

Authored by Jay Berkenbilt
1 parent 7f95ad5b

Improve the FILE* version of QPDF::processFile

include/qpdf/QPDF.hh
... ... @@ -55,10 +55,12 @@ class QPDF
55 55 // Parse a PDF from a stdio FILE*. The FILE must be open in
56 56 // binary mode and must be seekable. It may be open read only.
57 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 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 65 // Parse a PDF file loaded into a memory buffer. This works
64 66 // exactly like processFile except that the PDF file is in memory
... ... @@ -449,7 +451,7 @@ class QPDF
449 451 public:
450 452 FileInputSource();
451 453 void setFilename(char const* filename);
452   - void setFile(FILE* filep);
  454 + void setFile(char const* description, FILE* filep, bool close_file);
453 455 virtual ~FileInputSource();
454 456 virtual std::string const& getName() const;
455 457 virtual qpdf_offset_t tell();
... ...
libqpdf/QPDF.cc
... ... @@ -114,12 +114,13 @@ QPDF::FileInputSource::setFilename(char const* filename)
114 114 }
115 115  
116 116 void
117   -QPDF::FileInputSource::setFile(FILE* f)
  117 +QPDF::FileInputSource::setFile(
  118 + char const* description, FILE* filep, bool close_file)
118 119 {
119 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 124 this->seek(0, SEEK_SET);
124 125 }
125 126  
... ... @@ -347,11 +348,12 @@ QPDF::processFile(char const* filename, char const* password)
347 348 }
348 349  
349 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 354 FileInputSource* fi = new FileInputSource();
353 355 this->file = fi;
354   - fi->setFile(filep);
  356 + fi->setFile(description, filep, close_file);
355 357 parse(password);
356 358 }
357 359  
... ...
qpdf/test_driver.cc
... ... @@ -104,7 +104,7 @@ void runtest(int n, char const* filename)
104 104 QTC::TC("qpdf", "exercise processFile(FILE*)");
105 105 filep = QUtil::fopen_wrapper(std::string("open ") + filename,
106 106 fopen(filename, "rb"));
107   - pdf.processFile(filep);
  107 + pdf.processFile(filename, filep, false);
108 108 }
109 109 }
110 110 else
... ...