config.h.cmake | 2 ++ goo/JpegWriter.cc | 4 ++-- poppler/StdinCachedFile.cc | 8 ++++---- poppler/TextOutputDev.cc | 8 ++++---- utils/pdftocairo.cc | 14 ++++++++++---- utils/pdftoppm.cc | 8 ++++---- 6 files changed, 26 insertions(+), 18 deletions(-)
New commits: commit e2183097ad35038bb7266f181578020edf7cd08d Author: Peter Williams <pe...@newton.cx> Date: Wed Aug 18 10:39:21 2021 -0400 Fix up setmode calls To compile and work correctly on both Cygwin and MSVC, we should always call the function `_setmode` and check for either `_WIN32` or `__CYGWIN__` being defined. This fixes the MSVC build and corrects some behavior handling output to stdout on Cygwin. diff --git a/poppler/StdinCachedFile.cc b/poppler/StdinCachedFile.cc index 4727064e..90e38aaf 100644 --- a/poppler/StdinCachedFile.cc +++ b/poppler/StdinCachedFile.cc @@ -14,9 +14,9 @@ #include "StdinCachedFile.h" -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) # include <fcntl.h> // for O_BINARY -# include <io.h> // for setmode +# include <io.h> // for _setmode #endif #include <cstdio> @@ -25,8 +25,8 @@ size_t StdinCacheLoader::init(GooString *dummy, CachedFile *cachedFile) size_t read, size = 0; char buf[CachedFileChunkSize]; -#ifdef _WIN32 - setmode(fileno(stdin), O_BINARY); +#if defined(_WIN32) || defined(__CYGWIN__) + _setmode(fileno(stdin), O_BINARY); #endif CachedFileWriter writer = CachedFileWriter(cachedFile, nullptr); diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc index 041503f6..9583a700 100644 --- a/poppler/TextOutputDev.cc +++ b/poppler/TextOutputDev.cc @@ -58,9 +58,9 @@ #include <cfloat> #include <cctype> #include <algorithm> -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) # include <fcntl.h> // for O_BINARY -# include <io.h> // for setmode +# include <io.h> // for _setmode #endif #include "goo/gfile.h" #include "goo/gmem.h" @@ -5544,9 +5544,9 @@ TextOutputDev::TextOutputDev(const char *fileName, bool physLayoutA, double fixe if (fileName) { if (!strcmp(fileName, "-")) { outputStream = stdout; -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) // keep DOS from munging the end-of-line characters - setmode(fileno(stdout), O_BINARY); + _setmode(fileno(stdout), O_BINARY); #endif } else if ((outputStream = openFile(fileName, append ? "ab" : "wb"))) { needClose = true; diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc index 8cdb13d2..b9ee9129 100644 --- a/utils/pdftocairo.cc +++ b/utils/pdftocairo.cc @@ -50,6 +50,9 @@ #include <cmath> #include <cstring> #include <fcntl.h> +#if defined(_WIN32) || defined(__CYGWIN__) +# include <io.h> // for _setmode +#endif #include "parseargs.h" #include "goo/gmem.h" #include "goo/GooString.h" @@ -388,8 +391,8 @@ static void writePageImage(GooString *filename) return; if (filename->cmp("fd://0") == 0) { -#ifdef _WIN32 - setmode(fileno(stdout), O_BINARY); +#if defined(_WIN32) || defined(__CYGWIN__) + _setmode(fileno(stdout), O_BINARY); #endif file = stdout; } else @@ -558,9 +561,12 @@ static void beginDocument(GooString *inputFileName, GooString *outputFileName, d if (printToWin32) { output_file = nullptr; } else { - if (outputFileName->cmp("fd://0") == 0) + if (outputFileName->cmp("fd://0") == 0) { +#if defined(_WIN32) || defined(__CYGWIN__) + _setmode(fileno(stdout), O_BINARY); +#endif output_file = stdout; - else { + } else { output_file = fopen(outputFileName->c_str(), "wb"); if (!output_file) { fprintf(stderr, "Error opening output file %s\n", outputFileName->c_str()); diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc index 3e889b9c..76d35c8c 100644 --- a/utils/pdftoppm.cc +++ b/utils/pdftoppm.cc @@ -44,9 +44,9 @@ #include "config.h" #include <poppler-config.h> -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) # include <fcntl.h> // for O_BINARY -# include <io.h> // for setmode +# include <io.h> // for _setmode #endif #include <cstdio> #include <cmath> @@ -314,8 +314,8 @@ static void savePageSlice(PDFDoc *doc, SplashOutputDev *splashOut, int pg, int x exit(EXIT_FAILURE); } } else { -#ifdef _WIN32 - setmode(fileno(stdout), O_BINARY); +#if defined(_WIN32) || defined(__CYGWIN__) + _setmode(fileno(stdout), O_BINARY); #endif if (png) { commit db9aa98fb14f3e88f8ab9fd6fc5043a45ccba3fd Author: Peter Williams <pe...@newton.cx> Date: Wed Aug 18 10:38:11 2021 -0400 Map str{n,}casecmp to supported names on MSVC diff --git a/config.h.cmake b/config.h.cmake index 1d66c9ba..00e1445a 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -176,6 +176,8 @@ #if defined(_MSC_VER) || defined(__BORLANDC__) #define popen _popen #define pclose _pclose +#define strncasecmp _strnicmp +#define strcasecmp _stricmp #endif /* Number of bits in a file offset, on hosts where this is settable. */ commit e5cfc6977f716c4d42df4598cdd958fd865ed1a0 Author: Peter Williams <pe...@newton.cx> Date: Wed Aug 18 10:36:54 2021 -0400 JpegWriter: include poppler/Error.h sooner This is needed to avoid a symbol redefinition error on Windows/MSVC. diff --git a/goo/JpegWriter.cc b/goo/JpegWriter.cc index e5a4a3f2..f122c27a 100644 --- a/goo/JpegWriter.cc +++ b/goo/JpegWriter.cc @@ -19,12 +19,12 @@ #ifdef ENABLE_LIBJPEG +# include "poppler/Error.h" + extern "C" { # include <jpeglib.h> } -# include "poppler/Error.h" - struct JpegWriterPrivate { bool progressive;