aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-01-23 00:30:39 +0100
committerJay Berkenbilt <ejb@ql.org>2022-01-30 19:11:03 +0100
commite4905983d2751b4b0f7ae535cdffee2be7fbf36f (patch)
tree7e97f1f69b7d94ba136b87e12c39ab3cb95e9996 /libqpdf
parente5edfc786f0dab9435379a7420c17695128466b2 (diff)
downloadqpdf-e4905983d2751b4b0f7ae535cdffee2be7fbf36f.tar.zst
QPDFJob: convert outfilename to shared pointer
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFJob.cc33
-rw-r--r--libqpdf/QPDFJob_argv.cc6
2 files changed, 20 insertions, 19 deletions
diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc
index 00546652..129436d6 100644
--- a/libqpdf/QPDFJob.cc
+++ b/libqpdf/QPDFJob.cc
@@ -414,7 +414,6 @@ QPDFJob::QPDFJob() :
replace_input(false),
check_is_encrypted(false),
check_requires_password(false),
- outfilename(0),
m(new Members())
{
}
@@ -3257,7 +3256,8 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w)
{
w.registerProgressReporter(
new ProgressReporter(
- *(this->m->cout), this->m->message_prefix, o.outfilename));
+ *(this->m->cout), this->m->message_prefix,
+ o.outfilename.get()));
}
}
@@ -3268,27 +3268,27 @@ QPDFJob::doSplitPages(QPDF& pdf, bool& warnings)
// Generate output file pattern
std::string before;
std::string after;
- size_t len = strlen(o.outfilename);
- char* num_spot = strstr(const_cast<char*>(o.outfilename), "%d");
+ size_t len = strlen(o.outfilename.get());
+ char* num_spot = strstr(const_cast<char*>(o.outfilename.get()), "%d");
if (num_spot != 0)
{
QTC::TC("qpdf", "qpdf split-pages %d");
- before = std::string(o.outfilename,
- QIntC::to_size(num_spot - o.outfilename));
+ before = std::string(o.outfilename.get(),
+ QIntC::to_size(num_spot - o.outfilename.get()));
after = num_spot + 2;
}
else if ((len >= 4) &&
(QUtil::str_compare_nocase(
- o.outfilename + len - 4, ".pdf") == 0))
+ o.outfilename.get() + len - 4, ".pdf") == 0))
{
QTC::TC("qpdf", "qpdf split-pages .pdf");
- before = std::string(o.outfilename, len - 4) + "-";
- after = o.outfilename + len - 4;
+ before = std::string(o.outfilename.get(), len - 4) + "-";
+ after = o.outfilename.get() + len - 4;
}
else
{
QTC::TC("qpdf", "qpdf split-pages other");
- before = std::string(o.outfilename) + "-";
+ before = std::string(o.outfilename.get()) + "-";
}
if (shouldRemoveUnreferencedResources(pdf))
@@ -3385,24 +3385,25 @@ void
QPDFJob::writeOutfile(QPDF& pdf)
{
QPDFJob& o = *this; // QXXXQ
- std::string temp_out;
+ std::shared_ptr<char> temp_out;
if (o.replace_input)
{
// Append but don't prepend to the path to generate a
// temporary name. This saves us from having to split the path
// by directory and non-directory.
- temp_out = std::string(o.infilename.get()) + ".~qpdf-temp#";
+ temp_out = QUtil::make_shared_cstr(
+ std::string(o.infilename.get()) + ".~qpdf-temp#");
// o.outfilename will be restored to 0 before temp_out
// goes out of scope.
- o.outfilename = temp_out.c_str();
+ o.outfilename = temp_out;
}
- else if (strcmp(o.outfilename, "-") == 0)
+ else if (strcmp(o.outfilename.get(), "-") == 0)
{
o.outfilename = 0;
}
{
// Private scope so QPDFWriter will close the output file
- QPDFWriter w(pdf, o.outfilename);
+ QPDFWriter w(pdf, o.outfilename.get());
setWriterOptions(pdf, w);
w.write();
}
@@ -3427,7 +3428,7 @@ QPDFJob::writeOutfile(QPDF& pdf)
backup.append(1, '#');
}
QUtil::rename_file(o.infilename.get(), backup.c_str());
- QUtil::rename_file(temp_out.c_str(), o.infilename.get());
+ QUtil::rename_file(temp_out.get(), o.infilename.get());
if (warnings)
{
*(this->m->cerr)
diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc
index 0fb7d408..9ad02a02 100644
--- a/libqpdf/QPDFJob_argv.cc
+++ b/libqpdf/QPDFJob_argv.cc
@@ -72,7 +72,7 @@ ArgParser::argPositional(char* arg)
}
else if (o.outfilename == 0)
{
- o.outfilename = arg;
+ o.outfilename = QUtil::make_shared_cstr(arg);
}
else
{
@@ -1494,7 +1494,7 @@ ArgParser::doFinalChecks()
}
if (o.require_outfile && o.outfilename &&
- (strcmp(o.outfilename, "-") == 0))
+ (strcmp(o.outfilename.get(), "-") == 0))
{
if (o.split_pages)
{
@@ -1514,7 +1514,7 @@ ArgParser::doFinalChecks()
}
if ((! o.split_pages) &&
- QUtil::same_file(o.infilename.get(), o.outfilename))
+ QUtil::same_file(o.infilename.get(), o.outfilename.get()))
{
QTC::TC("qpdf", "qpdf same file error");
usage("input file and output file are the same;"