mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 19:08:59 +00:00
Call QUtil::safe_fopen in place of fopen
fopen was previuosly called wrapped by QUtil::fopen_wrapper, but QUtil::safe_fopen does this itself, which is less cumbersome.
This commit is contained in:
parent
7ccc9bd9d5
commit
ac4deac187
@ -1,5 +1,8 @@
|
|||||||
2013-02-28 Jay Berkenbilt <ejb@ql.org>
|
2013-02-28 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* New method QUtil::safe_fopen to wrap calls to fopen. This is
|
||||||
|
less cumbersome than calling QUtil::fopen_wrapper.
|
||||||
|
|
||||||
* Remove all calls to sprintf
|
* Remove all calls to sprintf
|
||||||
|
|
||||||
* New method QUtil::int_to_string_base to convert to octal or
|
* New method QUtil::int_to_string_base to convert to octal or
|
||||||
|
@ -54,6 +54,11 @@ namespace QUtil
|
|||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
int os_wrapper(std::string const& description, int status);
|
int os_wrapper(std::string const& description, int status);
|
||||||
|
|
||||||
|
// If the open fails, throws std::runtime_error. Otherwise, the
|
||||||
|
// FILE* is returned.
|
||||||
|
QPDF_DLL
|
||||||
|
FILE* safe_fopen(char const* filename, char const* mode);
|
||||||
|
|
||||||
// The FILE* argument is assumed to be the return of fopen. If
|
// The FILE* argument is assumed to be the return of fopen. If
|
||||||
// null, throw std::runtime_error. Otherwise, return the FILE*
|
// null, throw std::runtime_error. Otherwise, return the FILE*
|
||||||
// argument.
|
// argument.
|
||||||
|
@ -15,8 +15,7 @@ FileInputSource::setFilename(char const* filename)
|
|||||||
destroy();
|
destroy();
|
||||||
this->filename = filename;
|
this->filename = filename;
|
||||||
this->close_file = true;
|
this->close_file = true;
|
||||||
this->file = QUtil::fopen_wrapper(std::string("open ") + this->filename,
|
this->file = QUtil::safe_fopen(this->filename.c_str(), "rb");
|
||||||
fopen(this->filename.c_str(), "rb")); // XXXX
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -328,10 +328,7 @@ void MD5::encodeFile(char const *filename, int up_to_size)
|
|||||||
{
|
{
|
||||||
unsigned char buffer[1024];
|
unsigned char buffer[1024];
|
||||||
|
|
||||||
FILE *file = QUtil::fopen_wrapper(
|
FILE *file = QUtil::safe_fopen(filename, "rb");
|
||||||
std::string("MD5: open ") + filename,
|
|
||||||
fopen(filename, "rb")); // XXXX
|
|
||||||
|
|
||||||
size_t len;
|
size_t len;
|
||||||
int so_far = 0;
|
int so_far = 0;
|
||||||
int to_try = 1024;
|
int to_try = 1024;
|
||||||
|
@ -104,8 +104,7 @@ QPDFWriter::setOutputFilename(char const* filename)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
QTC::TC("qpdf", "QPDFWriter write to file");
|
QTC::TC("qpdf", "QPDFWriter write to file");
|
||||||
f = QUtil::fopen_wrapper(std::string("open ") + filename,
|
f = QUtil::safe_fopen(filename, "wb+");
|
||||||
fopen(filename, "wb+")); // XXXX
|
|
||||||
close_file = true;
|
close_file = true;
|
||||||
}
|
}
|
||||||
setOutputFile(description, f, close_file);
|
setOutputFile(description, f, close_file);
|
||||||
|
@ -37,9 +37,7 @@ void QTC::TC(char const* const scope, char const* const ccase, int n)
|
|||||||
}
|
}
|
||||||
cache.insert(std::make_pair(ccase, n));
|
cache.insert(std::make_pair(ccase, n));
|
||||||
|
|
||||||
FILE* tc =
|
FILE* tc = QUtil::safe_fopen(filename.c_str(), "ab");
|
||||||
QUtil::fopen_wrapper("open test coverage file (" + filename + ")",
|
|
||||||
fopen(filename.c_str(), "ab")); // XXXX
|
|
||||||
fprintf(tc, "%s %d\n", ccase, n);
|
fprintf(tc, "%s %d\n", ccase, n);
|
||||||
fclose(tc);
|
fclose(tc);
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,13 @@ QUtil::os_wrapper(std::string const& description, int status)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FILE*
|
||||||
|
QUtil::safe_fopen(char const* filename, char const* mode)
|
||||||
|
{
|
||||||
|
return fopen_wrapper(std::string("open ") + filename,
|
||||||
|
fopen(filename, mode)); // XXXX
|
||||||
|
}
|
||||||
|
|
||||||
FILE*
|
FILE*
|
||||||
QUtil::fopen_wrapper(std::string const& description, FILE* f)
|
QUtil::fopen_wrapper(std::string const& description, FILE* f)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <qpdf/Pl_AES_PDF.hh>
|
#include <qpdf/Pl_AES_PDF.hh>
|
||||||
#include <qpdf/Pl_StdioFile.hh>
|
#include <qpdf/Pl_StdioFile.hh>
|
||||||
|
#include <qpdf/QUtil.hh>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -89,20 +90,8 @@ int main(int argc, char* argv[])
|
|||||||
unsigned int hexkeylen = strlen(hexkey);
|
unsigned int hexkeylen = strlen(hexkey);
|
||||||
unsigned int keylen = hexkeylen / 2;
|
unsigned int keylen = hexkeylen / 2;
|
||||||
|
|
||||||
FILE* infile = fopen(infilename, "rb"); // XXXX
|
FILE* infile = QUtil::safe_fopen(infilename, "rb");
|
||||||
if (infile == 0)
|
FILE* outfile = QUtil::safe_fopen(outfilename, "wb");
|
||||||
{
|
|
||||||
std::cerr << "can't open " << infilename << std::endl;
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE* outfile = fopen(outfilename, "wb"); // XXXX
|
|
||||||
if (outfile == 0)
|
|
||||||
{
|
|
||||||
std::cerr << "can't open " << outfilename << std::endl;
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char* key = new unsigned char[keylen];
|
unsigned char* key = new unsigned char[keylen];
|
||||||
for (unsigned int i = 0; i < strlen(hexkey); i += 2)
|
for (unsigned int i = 0; i < strlen(hexkey); i += 2)
|
||||||
{
|
{
|
||||||
|
@ -2,33 +2,22 @@
|
|||||||
#include <qpdf/Pl_Flate.hh>
|
#include <qpdf/Pl_Flate.hh>
|
||||||
#include <qpdf/Pl_StdioFile.hh>
|
#include <qpdf/Pl_StdioFile.hh>
|
||||||
#include <qpdf/Pl_Count.hh>
|
#include <qpdf/Pl_Count.hh>
|
||||||
|
#include <qpdf/QUtil.hh>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
FILE* safe_fopen(char const* filename, char const* mode)
|
|
||||||
{
|
|
||||||
FILE* result = fopen(filename, mode); // XXXX
|
|
||||||
if (result == 0)
|
|
||||||
{
|
|
||||||
std::cerr << "fopen " << filename << " failed: " << strerror(errno) // XXXX
|
|
||||||
<< std::endl;
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void run(char const* filename)
|
void run(char const* filename)
|
||||||
{
|
{
|
||||||
std::string n1 = std::string(filename) + ".1";
|
std::string n1 = std::string(filename) + ".1";
|
||||||
std::string n2 = std::string(filename) + ".2";
|
std::string n2 = std::string(filename) + ".2";
|
||||||
std::string n3 = std::string(filename) + ".3";
|
std::string n3 = std::string(filename) + ".3";
|
||||||
|
|
||||||
FILE* o1 = safe_fopen(n1.c_str(), "wb");
|
FILE* o1 = QUtil::safe_fopen(n1.c_str(), "wb");
|
||||||
FILE* o2 = safe_fopen(n2.c_str(), "wb");
|
FILE* o2 = QUtil::safe_fopen(n2.c_str(), "wb");
|
||||||
FILE* o3 = safe_fopen(n3.c_str(), "wb");
|
FILE* o3 = QUtil::safe_fopen(n3.c_str(), "wb");
|
||||||
Pipeline* out1 = new Pl_StdioFile("o1", o1);
|
Pipeline* out1 = new Pl_StdioFile("o1", o1);
|
||||||
Pipeline* out2 = new Pl_StdioFile("o2", o2);
|
Pipeline* out2 = new Pl_StdioFile("o2", o2);
|
||||||
Pipeline* out3 = new Pl_StdioFile("o3", o3);
|
Pipeline* out3 = new Pl_StdioFile("o3", o3);
|
||||||
@ -46,7 +35,7 @@ void run(char const* filename)
|
|||||||
Pipeline* inf3 = new Pl_Flate("inf3", count3, Pl_Flate::a_inflate);
|
Pipeline* inf3 = new Pl_Flate("inf3", count3, Pl_Flate::a_inflate);
|
||||||
Pipeline* def3 = new Pl_Flate("def3", inf3, Pl_Flate::a_deflate);
|
Pipeline* def3 = new Pl_Flate("def3", inf3, Pl_Flate::a_deflate);
|
||||||
|
|
||||||
FILE* in1 = safe_fopen(filename, "rb");
|
FILE* in1 = QUtil::safe_fopen(filename, "rb");
|
||||||
unsigned char buf[1024];
|
unsigned char buf[1024];
|
||||||
size_t len;
|
size_t len;
|
||||||
while ((len = fread(buf, 1, sizeof(buf), in1)) > 0)
|
while ((len = fread(buf, 1, sizeof(buf), in1)) > 0)
|
||||||
@ -75,7 +64,7 @@ void run(char const* filename)
|
|||||||
fclose(o3);
|
fclose(o3);
|
||||||
|
|
||||||
// Now read the compressed data and write to the output uncompress pipeline
|
// Now read the compressed data and write to the output uncompress pipeline
|
||||||
FILE* in2 = safe_fopen(n1.c_str(), "rb");
|
FILE* in2 = QUtil::safe_fopen(n1.c_str(), "rb");
|
||||||
while ((len = fread(buf, 1, sizeof(buf), in2)) > 0)
|
while ((len = fread(buf, 1, sizeof(buf), in2)) > 0)
|
||||||
{
|
{
|
||||||
inf2->write(buf, len);
|
inf2->write(buf, len);
|
||||||
|
@ -26,10 +26,8 @@ int main(int argc, char* argv[])
|
|||||||
char* infilename = argv[1];
|
char* infilename = argv[1];
|
||||||
char* outfilename = argv[2];
|
char* outfilename = argv[2];
|
||||||
|
|
||||||
FILE* infile = QUtil::fopen_wrapper("open input file",
|
FILE* infile = QUtil::safe_fopen(infilename, "rb");
|
||||||
fopen(infilename, "rb")); // XXXX
|
FILE* outfile = QUtil::safe_fopen(outfilename, "wb");
|
||||||
FILE* outfile = QUtil::fopen_wrapper("open output file",
|
|
||||||
fopen(outfilename, "wb")); // XXXX
|
|
||||||
|
|
||||||
Pl_StdioFile out("output", outfile);
|
Pl_StdioFile out("output", outfile);
|
||||||
Pl_LZWDecoder decode("decode", &out, early_code_change);
|
Pl_LZWDecoder decode("decode", &out, early_code_change);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <qpdf/MD5.hh>
|
#include <qpdf/MD5.hh>
|
||||||
#include <qpdf/Pl_MD5.hh>
|
#include <qpdf/Pl_MD5.hh>
|
||||||
#include <qpdf/Pl_Discard.hh>
|
#include <qpdf/Pl_Discard.hh>
|
||||||
|
#include <qpdf/QUtil.hh>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -46,9 +47,7 @@ int main(int, char*[])
|
|||||||
Pl_MD5 p("MD5", &d);
|
Pl_MD5 p("MD5", &d);
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
FILE* f = fopen("md5.in", "rb"); // XXXX
|
FILE* f = QUtil::safe_fopen("md5.in", "rb");
|
||||||
if (f)
|
|
||||||
{
|
|
||||||
// buffer size < size of md5.in
|
// buffer size < size of md5.in
|
||||||
unsigned char buf[50];
|
unsigned char buf[50];
|
||||||
bool done = false;
|
bool done = false;
|
||||||
@ -68,7 +67,6 @@ int main(int, char*[])
|
|||||||
p.finish();
|
p.finish();
|
||||||
std::cout << p.getHexDigest() << std::endl;
|
std::cout << p.getHexDigest() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <qpdf/Pl_PNGFilter.hh>
|
#include <qpdf/Pl_PNGFilter.hh>
|
||||||
#include <qpdf/Pl_StdioFile.hh>
|
#include <qpdf/Pl_StdioFile.hh>
|
||||||
|
#include <qpdf/QUtil.hh>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -7,23 +8,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
FILE* safe_fopen(char const* filename, char const* mode)
|
|
||||||
{
|
|
||||||
FILE* result = fopen(filename, mode); // XXXX
|
|
||||||
if (result == 0)
|
|
||||||
{
|
|
||||||
std::cerr << "fopen " << filename << " failed: " << strerror(errno) // XXXX
|
|
||||||
<< std::endl;
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void run(char const* filename, bool encode, unsigned int columns)
|
void run(char const* filename, bool encode, unsigned int columns)
|
||||||
{
|
{
|
||||||
// Decode the file
|
// Decode the file
|
||||||
FILE* in = safe_fopen(filename, "rb");
|
FILE* in = QUtil::safe_fopen(filename, "rb");
|
||||||
FILE* o1 = safe_fopen("out", "wb");
|
FILE* o1 = QUtil::safe_fopen("out", "wb");
|
||||||
Pipeline* out = new Pl_StdioFile("out", o1);
|
Pipeline* out = new Pl_StdioFile("out", o1);
|
||||||
Pipeline* pl = new Pl_PNGFilter(
|
Pipeline* pl = new Pl_PNGFilter(
|
||||||
"png", out,
|
"png", out,
|
||||||
|
@ -19,7 +19,7 @@ before remove
|
|||||||
exception: remove file: No such file or directory
|
exception: remove file: No such file or directory
|
||||||
----
|
----
|
||||||
before fopen
|
before fopen
|
||||||
exception: fopen file: No such file or directory
|
exception: open /this/file/does/not/exist: No such file or directory
|
||||||
----
|
----
|
||||||
IN_TESTSUITE: 1: 1
|
IN_TESTSUITE: 1: 1
|
||||||
HAGOOGAMAGOOGLE: 0
|
HAGOOGAMAGOOGLE: 0
|
||||||
|
@ -62,12 +62,10 @@ void os_wrapper_test()
|
|||||||
|
|
||||||
void fopen_wrapper_test()
|
void fopen_wrapper_test()
|
||||||
{
|
{
|
||||||
FILE* f = 0;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::cout << "before fopen" << std::endl;
|
std::cout << "before fopen" << std::endl;
|
||||||
f = QUtil::fopen_wrapper("fopen file",
|
FILE* f = QUtil::safe_fopen("/this/file/does/not/exist", "r");
|
||||||
fopen("/this/file/does/not/exist", "r")); // XXXX
|
|
||||||
std::cout << "after fopen" << std::endl;
|
std::cout << "after fopen" << std::endl;
|
||||||
(void) fclose(f);
|
(void) fclose(f);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <qpdf/Pl_RC4.hh>
|
#include <qpdf/Pl_RC4.hh>
|
||||||
#include <qpdf/Pl_StdioFile.hh>
|
#include <qpdf/Pl_StdioFile.hh>
|
||||||
|
#include <qpdf/QUtil.hh>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -22,13 +23,7 @@ int main(int argc, char* argv[])
|
|||||||
unsigned char* key = new unsigned char[keylen + 1];
|
unsigned char* key = new unsigned char[keylen + 1];
|
||||||
key[keylen] = '\0';
|
key[keylen] = '\0';
|
||||||
|
|
||||||
FILE* infile = fopen(infilename, "rb"); // XXXX
|
FILE* infile = QUtil::safe_fopen(infilename, "rb");
|
||||||
if (infile == 0)
|
|
||||||
{
|
|
||||||
std::cerr << "can't open " << infilename << std::endl;
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < strlen(hexkey); i += 2)
|
for (unsigned int i = 0; i < strlen(hexkey); i += 2)
|
||||||
{
|
{
|
||||||
char t[3];
|
char t[3];
|
||||||
@ -40,12 +35,7 @@ int main(int argc, char* argv[])
|
|||||||
key[i/2] = static_cast<unsigned char>(val);
|
key[i/2] = static_cast<unsigned char>(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* outfile = fopen(outfilename, "wb"); // XXXX
|
FILE* outfile = QUtil::safe_fopen(outfilename, "wb");
|
||||||
if (outfile == 0)
|
|
||||||
{
|
|
||||||
std::cerr << "can't open " << outfilename << std::endl;
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
Pl_StdioFile* out = new Pl_StdioFile("stdout", outfile);
|
Pl_StdioFile* out = new Pl_StdioFile("stdout", outfile);
|
||||||
// Use a small buffer size (64) for testing
|
// Use a small buffer size (64) for testing
|
||||||
Pl_RC4* rc4 = new Pl_RC4("rc4", out, key, keylen, 64);
|
Pl_RC4* rc4 = new Pl_RC4("rc4", out, key, keylen, 64);
|
||||||
|
@ -8,6 +8,18 @@
|
|||||||
static char* whoami = 0;
|
static char* whoami = 0;
|
||||||
static qpdf_data qpdf = 0;
|
static qpdf_data qpdf = 0;
|
||||||
|
|
||||||
|
static FILE* safe_fopen(char const* filename, char const* mode)
|
||||||
|
{
|
||||||
|
FILE* f = fopen(filename, mode); /* XXXX */
|
||||||
|
if (f == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: unable to open %s: %s\n",
|
||||||
|
whoami, filename, strerror(errno)); /* XXXX */
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
static void report_errors()
|
static void report_errors()
|
||||||
{
|
{
|
||||||
qpdf_error e = 0;
|
qpdf_error e = 0;
|
||||||
@ -56,13 +68,7 @@ static void read_file_into_memory(char const* filename,
|
|||||||
size_t bytes_read = 0;
|
size_t bytes_read = 0;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
f = fopen(filename, "rb"); /* XXXX */
|
f = safe_fopen(filename, "rb");
|
||||||
if (f == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: unable to open %s: %s\n",
|
|
||||||
whoami, filename, strerror(errno)); /* XXXX */
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
*size = (unsigned long) ftell(f);
|
*size = (unsigned long) ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
@ -364,13 +370,7 @@ static void test16(char const* infile,
|
|||||||
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
|
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
|
||||||
qpdf_set_stream_data_mode(qpdf, qpdf_s_uncompress);
|
qpdf_set_stream_data_mode(qpdf, qpdf_s_uncompress);
|
||||||
qpdf_write(qpdf);
|
qpdf_write(qpdf);
|
||||||
f = fopen(outfile, "wb"); /* XXXX */
|
f = safe_fopen(outfile, "wb");
|
||||||
if (f == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: unable to open %s: %s\n",
|
|
||||||
whoami, outfile, strerror(errno)); /* XXXX */
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
buflen = qpdf_get_buffer_length(qpdf);
|
buflen = qpdf_get_buffer_length(qpdf);
|
||||||
buf = qpdf_get_buffer(qpdf);
|
buf = qpdf_get_buffer(qpdf);
|
||||||
fwrite(buf, 1, buflen, f);
|
fwrite(buf, 1, buflen, f);
|
||||||
|
@ -165,16 +165,14 @@ void runtest(int n, char const* filename1, char const* arg2)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
QTC::TC("qpdf", "exercise processFile(FILE*)");
|
QTC::TC("qpdf", "exercise processFile(FILE*)");
|
||||||
filep = QUtil::fopen_wrapper(std::string("open ") + filename1,
|
filep = QUtil::safe_fopen(filename1, "rb");
|
||||||
fopen(filename1, "rb")); // XXXX
|
|
||||||
pdf.processFile(filename1, filep, false);
|
pdf.processFile(filename1, filep, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QTC::TC("qpdf", "exercise processMemoryFile");
|
QTC::TC("qpdf", "exercise processMemoryFile");
|
||||||
FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename1,
|
FILE* f = QUtil::safe_fopen(filename1, "rb");
|
||||||
fopen(filename1, "rb")); // XXXX
|
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
size_t size = QUtil::tell(f);
|
size_t size = QUtil::tell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
@ -718,8 +716,7 @@ void runtest(int n, char const* filename1, char const* arg2)
|
|||||||
w.write();
|
w.write();
|
||||||
Buffer* b = w.getBuffer();
|
Buffer* b = w.getBuffer();
|
||||||
std::string const filename = (i == 0 ? "a.pdf" : "b.pdf");
|
std::string const filename = (i == 0 ? "a.pdf" : "b.pdf");
|
||||||
FILE* f = QUtil::fopen_wrapper("open " + filename,
|
FILE* f = QUtil::safe_fopen(filename.c_str(), "wb");
|
||||||
fopen(filename.c_str(), "wb")); // XXXX
|
|
||||||
fwrite(b->getBuffer(), b->getSize(), 1, f);
|
fwrite(b->getBuffer(), b->getSize(), 1, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
delete b;
|
delete b;
|
||||||
@ -802,8 +799,7 @@ void runtest(int n, char const* filename1, char const* arg2)
|
|||||||
checkPageContents(pages[12], "New page 12");
|
checkPageContents(pages[12], "New page 12");
|
||||||
|
|
||||||
// Exercise writing to FILE*
|
// Exercise writing to FILE*
|
||||||
FILE* out = QUtil::fopen_wrapper(std::string("open a.pdf"),
|
FILE* out = QUtil::safe_fopen("a.pdf", "wb");
|
||||||
fopen("a.pdf", "wb")); // XXXX
|
|
||||||
QPDFWriter w(pdf, "FILE* a.pdf", out, true);
|
QPDFWriter w(pdf, "FILE* a.pdf", out, true);
|
||||||
w.setStaticID(true);
|
w.setStaticID(true);
|
||||||
w.setStreamDataMode(qpdf_s_preserve);
|
w.setStreamDataMode(qpdf_s_preserve);
|
||||||
@ -1183,8 +1179,7 @@ void runtest(int n, char const* filename1, char const* arg2)
|
|||||||
w.setOutputPipeline(&p);
|
w.setOutputPipeline(&p);
|
||||||
w.write();
|
w.write();
|
||||||
PointerHolder<Buffer> b = p.getBuffer();
|
PointerHolder<Buffer> b = p.getBuffer();
|
||||||
FILE* f = QUtil::fopen_wrapper("open a.pdf",
|
FILE* f = QUtil::safe_fopen("a.pdf", "wb");
|
||||||
fopen("a.pdf", "wb")); // XXXX
|
|
||||||
fwrite(b->getBuffer(), b->getSize(), 1, f);
|
fwrite(b->getBuffer(), b->getSize(), 1, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user