aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2013-02-28 22:45:11 +0100
committerJay Berkenbilt <ejb@ql.org>2013-03-05 19:35:46 +0100
commitac4deac1873ca1bb570ffd479ed2cc1010762f89 (patch)
treee83f1d756f161b799483926676446241fc8ffeed /qpdf
parent7ccc9bd9d5463d29f3fc19a7f7718842e3b68be8 (diff)
downloadqpdf-ac4deac1873ca1bb570ffd479ed2cc1010762f89.tar.zst
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.
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qpdf-ctest.c28
-rw-r--r--qpdf/test_driver.cc15
2 files changed, 19 insertions, 24 deletions
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c
index faa202da..12f6a4cc 100644
--- a/qpdf/qpdf-ctest.c
+++ b/qpdf/qpdf-ctest.c
@@ -8,6 +8,18 @@
static char* whoami = 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()
{
qpdf_error e = 0;
@@ -56,13 +68,7 @@ static void read_file_into_memory(char const* filename,
size_t bytes_read = 0;
size_t len = 0;
- f = fopen(filename, "rb"); /* XXXX */
- if (f == NULL)
- {
- fprintf(stderr, "%s: unable to open %s: %s\n",
- whoami, filename, strerror(errno)); /* XXXX */
- exit(2);
- }
+ f = safe_fopen(filename, "rb");
fseek(f, 0, SEEK_END);
*size = (unsigned long) ftell(f);
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_stream_data_mode(qpdf, qpdf_s_uncompress);
qpdf_write(qpdf);
- f = fopen(outfile, "wb"); /* XXXX */
- if (f == NULL)
- {
- fprintf(stderr, "%s: unable to open %s: %s\n",
- whoami, outfile, strerror(errno)); /* XXXX */
- exit(2);
- }
+ f = safe_fopen(outfile, "wb");
buflen = qpdf_get_buffer_length(qpdf);
buf = qpdf_get_buffer(qpdf);
fwrite(buf, 1, buflen, f);
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index 41125be3..75f5b973 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -165,16 +165,14 @@ void runtest(int n, char const* filename1, char const* arg2)
else
{
QTC::TC("qpdf", "exercise processFile(FILE*)");
- filep = QUtil::fopen_wrapper(std::string("open ") + filename1,
- fopen(filename1, "rb")); // XXXX
+ filep = QUtil::safe_fopen(filename1, "rb");
pdf.processFile(filename1, filep, false);
}
}
else
{
QTC::TC("qpdf", "exercise processMemoryFile");
- FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename1,
- fopen(filename1, "rb")); // XXXX
+ FILE* f = QUtil::safe_fopen(filename1, "rb");
fseek(f, 0, SEEK_END);
size_t size = QUtil::tell(f);
fseek(f, 0, SEEK_SET);
@@ -718,8 +716,7 @@ void runtest(int n, char const* filename1, char const* arg2)
w.write();
Buffer* b = w.getBuffer();
std::string const filename = (i == 0 ? "a.pdf" : "b.pdf");
- FILE* f = QUtil::fopen_wrapper("open " + filename,
- fopen(filename.c_str(), "wb")); // XXXX
+ FILE* f = QUtil::safe_fopen(filename.c_str(), "wb");
fwrite(b->getBuffer(), b->getSize(), 1, f);
fclose(f);
delete b;
@@ -802,8 +799,7 @@ void runtest(int n, char const* filename1, char const* arg2)
checkPageContents(pages[12], "New page 12");
// Exercise writing to FILE*
- FILE* out = QUtil::fopen_wrapper(std::string("open a.pdf"),
- fopen("a.pdf", "wb")); // XXXX
+ FILE* out = QUtil::safe_fopen("a.pdf", "wb");
QPDFWriter w(pdf, "FILE* a.pdf", out, true);
w.setStaticID(true);
w.setStreamDataMode(qpdf_s_preserve);
@@ -1183,8 +1179,7 @@ void runtest(int n, char const* filename1, char const* arg2)
w.setOutputPipeline(&p);
w.write();
PointerHolder<Buffer> b = p.getBuffer();
- FILE* f = QUtil::fopen_wrapper("open a.pdf",
- fopen("a.pdf", "wb")); // XXXX
+ FILE* f = QUtil::safe_fopen("a.pdf", "wb");
fwrite(b->getBuffer(), b->getSize(), 1, f);
fclose(f);
}