.. SPDX-License-Identifier: MIT .. _library/stdio: ==================== Standard I/O (STDIO) ==================== ``#include "rcsw/stdio/printf.h"`` ``#include "rcsw/stdio/stdio.h"`` RCSW's stdio module provides a printf-family implementation and basic I/O helpers for environments where libc is not available. It wraps `eyalroz/printf `_ with the RCSW naming convention and platform abstraction layer. When to Use This Module ======================= Use the stdio module when: - You are building for a bare-metal target without libc (e.g., a bootstrap, bootloader, or hardware validation test). - You are using the ``simple`` ER plugin, which requires :c:func:`stdio_printf()` as its output function. - You need printf output routed through a custom BSP character output function rather than the system's ``putchar``. On POSIX targets where libc is available, you generally do not need this module. Disable it at build time with :cmake:variable:`RCSW_CONFIG_NO_STDIO` ``=YES`` if you are not using it. Platform Abstraction ==================== The stdio module routes character I/O through two CMake-configurable hooks: - :cmake:variable:`RCSW_CONFIG_STDIO_PUTCHAR` - :cmake:variable:`RCSW_CONFIG_STDIO_GETCHAR` They default to libc's ``putchar`` and ``getchar``. To route I/O elsewhere, such as a UART, set them to functions your platform layer provides. In a shared build those functions must be available when RCSW itself is linked; see :ref:`concepts/components`. printf Formatting ================= Float support, long long support, buffer sizes, and precision defaults are controlled by `eyalroz/printf `_ CMake options. To override an option, set it in your CMake invocation before including RCSW — CPM respects already-set cache variables. String and Integer Utilities ============================ ``#include "rcsw/stdio/stdio.h"`` Bare-metal replacements for common libc I/O and conversion functions. See the header for full signatures. Highlights: - :c:func:`stdio_puts()` writes a string without a trailing newline (unlike POSIX ``puts``). - :c:func:`stdio_atoi()` requires an explicit base argument; for base 16 an optional ``0x``/``0X`` prefix is skipped. - :c:func:`stdio_itoad()` and :c:func:`stdio_itoax()` are 32-bit only. ``#include "rcsw/stdio/string.h"`` has the string and memory routines (:c:func:`stdio_strlen`, :c:func:`stdio_strcmp`, :c:func:`stdio_memcpy`, ...) and ASCII-only character class functions (:c:func:`stdio_isdigit`, :c:func:`stdio_ishex`, :c:func:`stdio_isalpha`, ...). Like ```` they take an ``int`` and return 1 or 0, but they don't depend on the locale, and a negative ``char`` value is in no class.