From 36615cfa85c6495c663a47cc6580c2539bec2968 Mon Sep 17 00:00:00 2001 From: Jonathan Liu Date: Sat, 31 Jul 2010 21:56:28 +1000 Subject: [PATCH] Fix binary I/O on Windows when using redirection --- poppler/StdinCachedFile.cc | 8 ++++++++ utils/pdftoppm.cc | 8 ++++++++ 2 files changed, 16 insertions(+), 0 deletions(-) diff --git a/poppler/StdinCachedFile.cc b/poppler/StdinCachedFile.cc index 4bfc31e..2c1404b 100644 --- a/poppler/StdinCachedFile.cc +++ b/poppler/StdinCachedFile.cc @@ -13,6 +13,10 @@ #include "StdinCachedFile.h" +#ifdef _WIN32 +#include // for O_BINARY +#include // for setmode +#endif #include size_t StdinCacheLoader::init(GooString *dummy, CachedFile *cachedFile) @@ -20,6 +24,10 @@ size_t StdinCacheLoader::init(GooString *dummy, CachedFile *cachedFile) size_t read, size = 0; char buf[CachedFileChunkSize]; +#if _WIN32 + setmode(fileno(stdin), O_BINARY); +#endif + CachedFileWriter writer = CachedFileWriter (cachedFile, NULL); do { read = fread(buf, 1, CachedFileChunkSize, stdin); diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc index ed64fea..014de2a 100644 --- a/utils/pdftoppm.cc +++ b/utils/pdftoppm.cc @@ -29,6 +29,10 @@ #include "config.h" #include +#ifdef _WIN32 +#include // for O_BINARY +#include // for setmode +#endif #include #include #include "parseargs.h" @@ -178,6 +182,10 @@ static void savePageSlice(PDFDoc *doc, bitmap->writePNMFile(ppmFile); } } else { +#if _WIN32 + setmode(fileno(stdout), O_BINARY); +#endif + if (png) { bitmap->writeImgFile(splashFormatPng, stdout, x_resolution, y_resolution); } else if (jpeg) { -- 1.7.1.1