From 6b33edf2a4497705e9b69f8347a9349f3abe6123 Mon Sep 17 00:00:00 2001 From: Jonathan Liu Date: Sat, 31 Jul 2010 11:51:49 +1000 Subject: [PATCH] Fix binary I/O on Windows when using redirection --- utils/pdffonts.cc | 8 ++++++++ utils/pdfimages.cc | 8 ++++++++ utils/pdfinfo.cc | 8 ++++++++ utils/pdftoabw.cc | 8 ++++++++ utils/pdftohtml.cc | 8 ++++++++ utils/pdftoppm.cc | 8 ++++++++ utils/pdftops.cc | 8 ++++++++ utils/pdftotext.cc | 8 ++++++++ 8 files changed, 64 insertions(+), 0 deletions(-) diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc index 81b20e4..1a2c609 100644 --- a/utils/pdffonts.cc +++ b/utils/pdffonts.cc @@ -24,6 +24,7 @@ #include "config.h" #include +#include #include #include #include @@ -93,6 +94,13 @@ static int fontsLen; static int fontsSize; int main(int argc, char *argv[]) { +#if _WIN32 + _fmode = _O_BINARY; + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + _setmode(_fileno(stderr), _O_BINARY); +#endif + PDFDoc *doc; GooString *fileName; GooString *ownerPW, *userPW; diff --git a/utils/pdfimages.cc b/utils/pdfimages.cc index ffa7991..af3f271 100644 --- a/utils/pdfimages.cc +++ b/utils/pdfimages.cc @@ -25,6 +25,7 @@ #include "config.h" #include +#include #include #include #include @@ -81,6 +82,13 @@ static const ArgDesc argDesc[] = { }; int main(int argc, char *argv[]) { +#if _WIN32 + _fmode = _O_BINARY; + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + _setmode(_fileno(stderr), _O_BINARY); +#endif + PDFDoc *doc; GooString *fileName; char *imgRoot; diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc index 2abe8b4..ef8a2b6 100644 --- a/utils/pdfinfo.cc +++ b/utils/pdfinfo.cc @@ -24,6 +24,7 @@ #include "config.h" #include +#include #include #include #include @@ -97,6 +98,13 @@ static const ArgDesc argDesc[] = { }; int main(int argc, char *argv[]) { +#if _WIN32 + _fmode = _O_BINARY; + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + _setmode(_fileno(stderr), _O_BINARY); +#endif + PDFDoc *doc; GooString *fileName; GooString *ownerPW, *userPW; diff --git a/utils/pdftoabw.cc b/utils/pdftoabw.cc index 5a53281..aa24d55 100644 --- a/utils/pdftoabw.cc +++ b/utils/pdftoabw.cc @@ -23,6 +23,7 @@ #include "config.h" #include +#include #include #include #include @@ -89,6 +90,13 @@ static const ArgDesc argDesc[] = { }; int main(int argc, char *argv[]) { +#if _WIN32 + _fmode = _O_BINARY; + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + _setmode(_fileno(stderr), _O_BINARY); +#endif + GBool ok; PDFDoc *doc = NULL; GooString *fileName = NULL; diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc index 3c74c6e..e97c870 100644 --- a/utils/pdftohtml.cc +++ b/utils/pdftohtml.cc @@ -23,6 +23,7 @@ #include "config.h" #include +#include #include #include #include @@ -129,6 +130,13 @@ static const ArgDesc argDesc[] = { }; int main(int argc, char *argv[]) { +#if _WIN32 + _fmode = _O_BINARY; + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + _setmode(_fileno(stderr), _O_BINARY); +#endif + PDFDoc *doc = NULL; GooString *fileName = NULL; GooString *docTitle = NULL; diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc index ed64fea..3ab8fa3 100644 --- a/utils/pdftoppm.cc +++ b/utils/pdftoppm.cc @@ -29,6 +29,7 @@ #include "config.h" #include +#include #include #include #include "parseargs.h" @@ -201,6 +202,13 @@ static int numberOfCharacters(unsigned int n) } int main(int argc, char *argv[]) { +#if _WIN32 + _fmode = _O_BINARY; + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + _setmode(_fileno(stderr), _O_BINARY); +#endif + PDFDoc *doc; GooString *fileName = NULL; char *ppmRoot = NULL; diff --git a/utils/pdftops.cc b/utils/pdftops.cc index 0bc43a1..abd37b9 100644 --- a/utils/pdftops.cc +++ b/utils/pdftops.cc @@ -28,6 +28,7 @@ #include "config.h" #include +#include #include #include #include @@ -179,6 +180,13 @@ static const ArgDesc argDesc[] = { }; int main(int argc, char *argv[]) { +#if _WIN32 + _fmode = _O_BINARY; + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + _setmode(_fileno(stderr), _O_BINARY); +#endif + PDFDoc *doc; GooString *fileName; GooString *psFileName; diff --git a/utils/pdftotext.cc b/utils/pdftotext.cc index d4e004b..376a4a4 100644 --- a/utils/pdftotext.cc +++ b/utils/pdftotext.cc @@ -27,6 +27,7 @@ #include "config.h" #include +#include #include #include #include @@ -123,6 +124,13 @@ static const ArgDesc argDesc[] = { }; int main(int argc, char *argv[]) { +#if _WIN32 + _fmode = _O_BINARY; + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + _setmode(_fileno(stderr), _O_BINARY); +#endif + PDFDoc *doc; GooString *fileName; GooString *textFileName; -- 1.7.1.1