| 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 | 464 | 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 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 464 times.
|
464 | FwSizeType capped_size = (size <= std::numeric_limits<size_t>::max()) ? size : std::numeric_limits<size_t>::max(); |
| 19 |
1/2✓ Branch 0 taken 464 times.
✗ Branch 1 not taken.
|
464 | if (message != nullptr) { |
| 20 | 464 | (void)::fwrite(message, sizeof(CHAR), static_cast<size_t>(capped_size), this->m_handle.m_file_descriptor); | |
| 21 | 464 | (void)::fflush(this->m_handle.m_file_descriptor); | |
| 22 | } | ||
| 23 | 464 | } | |
| 24 | |||
| 25 | ✗ | ConsoleHandle* PosixConsole::getHandle() { | |
| 26 | ✗ | return &this->m_handle; | |
| 27 | } | ||
| 28 | |||
| 29 | ✗ | void PosixConsole ::setOutputStream(Stream stream) { | |
| 30 | ✗ | switch (stream) { | |
| 31 | ✗ | case STANDARD_OUT: | |
| 32 | ✗ | this->m_handle.m_file_descriptor = stdout; | |
| 33 | ✗ | break; | |
| 34 | ✗ | case STANDARD_ERROR: | |
| 35 | ✗ | this->m_handle.m_file_descriptor = stderr; | |
| 36 | ✗ | break; | |
| 37 | ✗ | default: | |
| 38 | ✗ | FW_ASSERT(false); | |
| 39 | ✗ | break; | |
| 40 | } | ||
| 41 | ✗ | } | |
| 42 | |||
| 43 | } // namespace Console | ||
| 44 | } // namespace Posix | ||
| 45 | } // namespace Os | ||
| 46 |