Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions guetzli/guetzli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include "guetzli/processor.h"
#include "guetzli/quality.h"
#include "guetzli/stats.h"
#if _WIN32 | _WIN64
#include <fcntl.h>
#include <io.h>
#endif

namespace {

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down