| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/Posix/Console.cpp | ||
| 3 | // \brief posix implementation for Os::Console | ||
| 4 | // ====================================================================== | ||
| 5 | #include <Fw/Types/Assert.hpp> | ||
| 6 | #include <Os/Posix/Console.hpp> | ||
| 7 | #include <cstdio> | ||
| 8 | #include <limits> | ||
| 9 | |||
| 10 | namespace Os { | ||
| 11 | namespace Posix { | ||
| 12 | namespace Console { | ||
| 13 | |||
| 14 | ✗ | void PosixConsole::writeMessage(const CHAR* message, const FwSizeType size) { | |
| 15 | // size_t is defined as different sizes on different platforms. Since FwSizeType is likely larger than size_t | ||
| 16 | // on these platforms, and the user is unlikely to console-log more than size_t-max data, we cap the total | ||
| 17 | // size at the limit of the interface. | ||
| 18 | ✗ | FwSizeType capped_size = (size <= std::numeric_limits<size_t>::max()) ? size : std::numeric_limits<size_t>::max(); | |
| 19 | ✗ | if (message != nullptr) { | |
| 20 | ✗ | (void)::fwrite(message, sizeof(CHAR), static_cast<size_t>(capped_size), this->m_handle.m_file_descriptor); | |
| 21 | ✗ | (void)::fflush(this->m_handle.m_file_descriptor); | |
| 22 | } | ||
| 23 | ✗ | } | |
| 24 | |||
| 25 | 3 | ConsoleHandle* PosixConsole::getHandle() { | |
| 26 | 3 | return &this->m_handle; | |
| 27 | } | ||
| 28 | |||
| 29 | 2 | void PosixConsole ::setOutputStream(Stream stream) { | |
| 30 |
2/3✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | switch (stream) { |
| 31 | 1 | case STANDARD_OUT: | |
| 32 | 1 | this->m_handle.m_file_descriptor = stdout; | |
| 33 | 1 | break; | |
| 34 | 1 | case STANDARD_ERROR: | |
| 35 | 1 | this->m_handle.m_file_descriptor = stderr; | |
| 36 | 1 | break; | |
| 37 | ✗ | default: | |
| 38 | ✗ | FW_ASSERT(false); | |
| 39 | ✗ | break; | |
| 40 | } | ||
| 41 | 2 | } | |
| 42 | |||
| 43 | } // namespace Console | ||
| 44 | } // namespace Posix | ||
| 45 | } // namespace Os | ||
| 46 |