aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/qpdf/QUtil.hh3
-rw-r--r--libqpdf/QPDFWriter.cc1
-rw-r--r--libqpdf/QUtil.cc10
-rw-r--r--qpdf/qpdf.cc22
-rw-r--r--qpdf/qtest/qpdf.test9
-rw-r--r--qpdf/test_driver.cc4
-rw-r--r--zlib-flate/zlib-flate.cc5
7 files changed, 46 insertions, 8 deletions
diff --git a/include/qpdf/QUtil.hh b/include/qpdf/QUtil.hh
index ffa7dda5..f5ff3323 100644
--- a/include/qpdf/QUtil.hh
+++ b/include/qpdf/QUtil.hh
@@ -32,6 +32,9 @@ namespace QUtil
char* copy_string(std::string const&);
+ // Set stdout to binary mode
+ void binary_stdout();
+
// Get the value of an environment variable in a portable fashion.
// Returns true iff the variable is defined. If `value' is
// non-null, initializes it with the value of the variable.
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index eb146bd2..b4b4b6d2 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -50,6 +50,7 @@ QPDFWriter::QPDFWriter(QPDF& pdf, char const* filename) :
this->filename = "standard output";
QTC::TC("qpdf", "QPDFWriter write to stdout");
file = stdout;
+ QUtil::binary_stdout();
}
else
{
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index 3ac467d4..c3df35da 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -5,9 +5,11 @@
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
+#include <fcntl.h>
#ifdef _WIN32
#include <Windows.h>
#include <direct.h>
+#include <io.h>
#else
#include <unistd.h>
#endif
@@ -104,6 +106,14 @@ QUtil::copy_string(std::string const& str)
return result;
}
+void
+QUtil::binary_stdout()
+{
+#ifdef _WIN32
+ _setmode(_fileno(stdout), _O_BINARY);
+#endif
+}
+
bool
QUtil::get_env(std::string const& var, std::string* value)
{
diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc
index 90025f46..7bf41936 100644
--- a/qpdf/qpdf.cc
+++ b/qpdf/qpdf.cc
@@ -2,6 +2,11 @@
#include <iostream>
#include <string.h>
#include <stdlib.h>
+#include <fcntl.h>
+
+#ifdef _WIN32
+# include <io.h>
+#endif
#include <qpdf/QUtil.hh>
#include <qpdf/QTC.hh>
@@ -15,7 +20,7 @@
static int const EXIT_ERROR = 2;
static int const EXIT_WARNING = 3;
-static char const* whoami = 0;
+static char* whoami = 0;
// Note: let's not be too noisy about documenting the fact that this
// software purposely fails to enforce the distinction between user
@@ -429,7 +434,12 @@ parse_encrypt_options(
int main(int argc, char* argv[])
{
- if ((whoami = strrchr(argv[0], '/')) == NULL)
+#ifdef _WIN32
+ char pathsep = '\\';
+#else
+ char pathsep = '/';
+#endif
+ if ((whoami = strrchr(argv[0], pathsep)) == NULL)
{
whoami = argv[0];
}
@@ -437,6 +447,13 @@ int main(int argc, char* argv[])
{
++whoami;
}
+#ifdef _WIN32
+ if ((strlen(whoami) > 4) &&
+ (strcmp(whoami + strlen(whoami) - 4, ".exe") == 0))
+ {
+ whoami[strlen(whoami) - 4] = '\0';
+ }
+#endif
// For libtool's sake....
if (strncmp(whoami, "lt-", 3) == 0)
{
@@ -790,6 +807,7 @@ int main(int argc, char* argv[])
}
else
{
+ QUtil::binary_stdout();
Pl_StdioFile out("stdout", stdout);
obj.pipeStreamData(&out, filter, normalize, false);
}
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index 55f7c594..508f1dd0 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -267,7 +267,8 @@ for (my $i = 1; $i <= scalar(@goodfiles); ++$i)
$td->runtest("$goodfiles[$i-1]",
{$td->COMMAND => "test_driver $n good$i.pdf"},
{$td->FILE => "good$i.out",
- $td->EXIT_STATUS => 0});
+ $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
my $xflags = $goodtest_flags{$i} || '';
check_pdf("create qdf",
"qpdf --static-id -qdf $xflags good$i.pdf",
@@ -461,7 +462,8 @@ $td->runtest("unfilterable stream data",
{$td->COMMAND => "qpdf encrypted-with-images.pdf" .
" --show-object=8 --filtered-stream-data"},
{$td->FILE => "show-unfilterable.out",
- $td->EXIT_STATUS => 2});
+ $td->EXIT_STATUS => 2},
+ $td->NORMALIZE_NEWLINES);
$td->runtest("show-xref-by-id",
{$td->COMMAND => "qpdf encrypted-with-images.pdf" .
@@ -837,7 +839,8 @@ foreach my $file (@files)
$td->runtest("check status",
{$td->COMMAND => "qpdf --check a.pdf"},
{$td->FILE => "$base.$n.check",
- $td->EXIT_STATUS => 0});
+ $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
compare_pdfs($file, "a.pdf");
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index cdaa4cc5..192577c5 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -126,6 +126,7 @@ void runtest(int n, char const* filename)
std::cout << "Raw stream data:" << std::endl;
std::cout.flush();
+ QUtil::binary_stdout();
PointerHolder<Pl_StdioFile> out = new Pl_StdioFile("raw", stdout);
qtest.pipeStreamData(out.getPointer(), false, false, false);
@@ -133,6 +134,7 @@ void runtest(int n, char const* filename)
if (qtest.pipeStreamData(0, true, false, false))
{
std::cout.flush();
+ QUtil::binary_stdout();
out = new Pl_StdioFile("filtered", stdout);
qtest.pipeStreamData(out.getPointer(), true, false, false);
std::cout << std::endl << "End of stream data" << std::endl;
@@ -172,6 +174,7 @@ void runtest(int n, char const* filename)
QPDFObjectHandle kids = pages.getKey("/Kids");
QPDFObjectHandle page = kids.getArrayItem(1); // second page
QPDFObjectHandle contents = page.getKey("/Contents");
+ QUtil::binary_stdout();
PointerHolder<Pl_StdioFile> out = new Pl_StdioFile("filtered", stdout);
contents.pipeStreamData(out.getPointer(), true, false, false);
}
@@ -183,6 +186,7 @@ void runtest(int n, char const* filename)
QPDFObjectHandle stream = streams.getArrayItem(i);
std::cout << "-- stream " << i << " --" << std::endl;
std::cout.flush();
+ QUtil::binary_stdout();
PointerHolder<Pl_StdioFile> out =
new Pl_StdioFile("tokenized stream", stdout);
stream.pipeStreamData(out.getPointer(), true, true, false);
diff --git a/zlib-flate/zlib-flate.cc b/zlib-flate/zlib-flate.cc
index f46a82dd..b5ba8e5e 100644
--- a/zlib-flate/zlib-flate.cc
+++ b/zlib-flate/zlib-flate.cc
@@ -1,5 +1,6 @@
#include <qpdf/Pl_Flate.hh>
#include <qpdf/Pl_StdioFile.hh>
+#include <qpdf/QUtil.hh>
#include <stdio.h>
#include <string.h>
@@ -63,9 +64,7 @@ int main(int argc, char* argv[])
usage();
}
-#ifdef _WIN32
- _setmode(_fileno(stdout), _O_BINARY);
-#endif
+ QUtil::binary_stdout();
Pl_StdioFile* out = new Pl_StdioFile("stdout", stdout);
Pl_Flate* flate = new Pl_Flate("flate", out, action);