Fix for win32 binary i/o

PiperOrigin-RevId: 516951027
pull/13171/head
Joshua Haberman 2 years ago committed by Copybara-Service
parent b7dcc1cf4c
commit 2e9278de50
  1. 11
      upbc/plugin.h

@ -26,8 +26,14 @@
#ifndef UPB_UPBC_PLUGIN_H_
#define UPB_UPBC_PLUGIN_H_
#include <stdio.h>
#include <string>
#include <vector>
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
#endif
// begin:google_only
// #ifndef UPB_BOOTSTRAP_STAGE0
@ -156,7 +162,10 @@ class Plugin {
std::string ReadAllStdinBinary() {
std::string data;
stdin = freopen(nullptr, "rb", stdin);
#ifdef _WIN32
setmode(STDIN_FILENO, _O_BINARY);
setmode(STDOUT_FILENO, _O_BINARY);
#endif
char buf[4096];
while (size_t len = fread(buf, 1, sizeof(buf), stdin)) {
data.append(buf, len);

Loading…
Cancel
Save