MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / read_stdin

Function read_stdin

test/process_test.cpp:62–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 "deserunt mollit anim id est laborum.";
61
62static 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
88TEST_CASE(string_stdin)
89{

Callers 1

mainFunction · 0.70

Calls 5

dataMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected