| 60 | "deserunt mollit anim id est laborum."; |
| 61 | |
| 62 | static std::vector<char> read_stdin() |
| 63 | { |
| 64 | std::vector<char> result; |
| 65 | std::array<char, 1024> buffer{}; |
| 66 | std::size_t len = 0; |
| 67 | #ifdef _WIN32 |
| 68 | // Set stream translation mode to BINARY to suppress translations. |
| 69 | // https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode?view=msvc-170 |
| 70 | auto old_mode = _setmode(_fileno(stdin), _O_BINARY); |
| 71 | if(old_mode == -1) |
| 72 | throw std::runtime_error{"failure setting IO mode to binary"}; |
| 73 | #endif |
| 74 | while((len = std::fread(buffer.data(), 1, buffer.size(), stdin)) > 0) |
| 75 | { |
| 76 | if(std::ferror(stdin) != 0 and std::feof(stdin) == 0) |
| 77 | throw std::runtime_error{std::strerror(errno)}; |
| 78 | |
| 79 | result.insert(result.end(), buffer.begin(), buffer.begin() + len); |
| 80 | } |
| 81 | #ifdef _WIN32 |
| 82 | // Reset to the previously set translation mode. |
| 83 | _setmode(_fileno(stdin), old_mode); |
| 84 | #endif |
| 85 | return result; |
| 86 | } |
| 87 | |
| 88 | TEST_CASE(string_stdin) |
| 89 | { |