Commit 78db117e9cc6aa09cc7d4d43ea8f9bc68feef306

Authored by Josh Klontz
1 parent dcc2c93c

windows standard io fix for binary data

Showing 1 changed file with 21 additions and 0 deletions
openbr/plugins/gallery.cpp
... ... @@ -39,6 +39,11 @@
39 39 #include "MatlabIOContainer.hpp"
40 40 #endif
41 41  
  42 +#ifdef _WIN32
  43 +#include <io.h>
  44 +#include <fcntl.h>
  45 +#endif // _WIN32
  46 +
42 47 namespace br
43 48 {
44 49  
... ... @@ -96,11 +101,27 @@ class BinaryGallery : public Gallery
96 101 void init()
97 102 {
98 103 const QString baseName = file.baseName();
  104 +
99 105 if (baseName == "stdin") {
  106 +#ifdef _WIN32
  107 + if(_setmode(_fileno(stdin), _O_BINARY) == -1)
  108 + qFatal("Failed to set stdin to binary mode!");
  109 +#endif // _WIN32
  110 +
100 111 gallery.open(stdin, QFile::ReadOnly);
101 112 } else if (baseName == "stdout") {
  113 +#ifdef _WIN32
  114 + if(_setmode(_fileno(stdout), _O_BINARY) == -1)
  115 + qFatal("Failed to set stdout to binary mode!");
  116 +#endif // _WIN32
  117 +
102 118 gallery.open(stdout, QFile::WriteOnly);
103 119 } else if (baseName == "stderr") {
  120 +#ifdef _WIN32
  121 + if(_setmode(_fileno(stderr), _O_BINARY) == -1)
  122 + qFatal("Failed to set stderr to binary mode!");
  123 +#endif // _WIN32
  124 +
104 125 gallery.open(stderr, QFile::WriteOnly);
105 126 } else {
106 127 gallery.setFileName(file);
... ...