| 94 | // ------------------------------------------------------------------------------------------------- |
| 95 | |
| 96 | InputStream::InputStream(const std::string& filepath, Reporter& report) : |
| 97 | filepath(filepath) { |
| 98 | if (filepath == "-") { |
| 99 | #if defined(_WIN32) |
| 100 | // Set "stdin" to binary mode |
| 101 | const auto setmodeResult = _setmode(_fileno(stdin), _O_BINARY); |
| 102 | if (setmodeResult == -1) |
| 103 | report.fatal(rc::IO_FAILURE, "Failed to set stdin mode to binary: {}.", setmodeResult); |
| 104 | // #else |
| 105 | // std::freopen(nullptr, "rb", stdin); |
| 106 | #endif |
| 107 | |
| 108 | // Read everything from stdin into memory to enable random access |
| 109 | stdinBuffer << std::cin.rdbuf(); |
| 110 | activeStream = &stdinBuffer; |
| 111 | } else { |
| 112 | file.open(DecodeUTF8Path(filepath).c_str(), std::ios::binary | std::ios::in); |
| 113 | if (!file) |
| 114 | report.fatal(rc::IO_FAILURE, "Could not open input file \"{}\": {}.", filepath, errnoMessage()); |
| 115 | activeStream = &file; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // ------------------------------------------------------------------------------------------------- |
| 120 |
nothing calls this directly
no test coverage detected