| 119 | // ------------------------------------------------------------------------------------------------- |
| 120 | |
| 121 | OutputStream::OutputStream(const std::string& filepath, Reporter& report) : |
| 122 | filepath(filepath) { |
| 123 | |
| 124 | if (filepath == "-") { |
| 125 | #if defined(_WIN32) |
| 126 | // Set "stdout" to binary mode |
| 127 | const auto setmodeResult = _setmode(_fileno(stdout), _O_BINARY); |
| 128 | if (setmodeResult == -1) |
| 129 | report.fatal(rc::IO_FAILURE, "Failed to set stdout mode to binary: {}.", setmodeResult); |
| 130 | // #else |
| 131 | // std::freopen(nullptr, "wb", stdout); |
| 132 | #endif |
| 133 | file = stdout; |
| 134 | } else { |
| 135 | #if defined(_WIN32) |
| 136 | file = _wfopen(DecodeUTF8Path(filepath).c_str(), L"wb"); |
| 137 | #else |
| 138 | file = fopen(DecodeUTF8Path(filepath).c_str(), "wb"); |
| 139 | #endif |
| 140 | if (!file) |
| 141 | report.fatal(rc::IO_FAILURE, "Could not open output file \"{}\": {}.", filepath, errnoMessage()); |
| 142 | } |
| 143 | |
| 144 | // TODO: Investigate and resolve the portability issue with the C++ streams. The issue will most likely |
| 145 | // be in StreambufStream's position reporting and seeking. Currently a fallback is implemented in C above. |
| 146 | // if (filepath == "-") { |
| 147 | // #if defined(_WIN32) |
| 148 | // // Set "stdout" to binary mode |
| 149 | // const auto setmodeResult = _setmode(_fileno(stdout), _O_BINARY); |
| 150 | // if (setmodeResult == -1) |
| 151 | // report.fatal(rc::IO_FAILURE, "Failed to set stdout mode to binary: {}", setmodeResult); |
| 152 | // // #else |
| 153 | // // std::freopen(nullptr, "wb", stdout); |
| 154 | // #endif |
| 155 | // activeStream = &std::cout; |
| 156 | // } else { |
| 157 | // file.open(DecodeUTF8Path(filepath).c_str(), std::ios::binary | std::ios::out); |
| 158 | // if (!file) |
| 159 | // report.fatal(rc::IO_FAILURE, "Could not open output file \"{}\": {}", filepath, errnoMessage()); |
| 160 | // activeStream = &file; |
| 161 | // } |
| 162 | } |
| 163 | |
| 164 | OutputStream::~OutputStream() { |
| 165 | if (file != stdout) |
nothing calls this directly
no test coverage detected