diff --git a/guetzli/guetzli.cc b/guetzli/guetzli.cc index fb6cd0a9..b1228da6 100644 --- a/guetzli/guetzli.cc +++ b/guetzli/guetzli.cc @@ -28,6 +28,10 @@ #include "guetzli/processor.h" #include "guetzli/quality.h" #include "guetzli/stats.h" +#if _WIN32 | _WIN64 +#include +#include +#endif namespace { @@ -160,6 +164,12 @@ std::string ReadFileOrDie(const char* filename) { exit(1); } +#if _WIN32 | _WIN64 + if (read_from_stdin) { + _setmode(_fileno(stdin), _O_BINARY); + } +#endif + std::string result; off_t buffer_size = 8192; @@ -196,6 +206,12 @@ void WriteFileOrDie(const char* filename, const std::string& contents) { perror("Can't open output file for writing"); exit(1); } + +#if _WIN32 | _WIN64 + if (write_to_stdout) { + _setmode(_fileno(f), _O_BINARY); + } +#endif if (fwrite(contents.data(), 1, contents.size(), f) != contents.size()) { perror("fwrite"); exit(1);