1.. _c_library_minimal:
2
3Minimal libc
4############
5
6The most basic C library, named "minimal libc", is part of the Zephyr codebase
7and provides the minimal subset of the standard C library required to meet the
8needs of Zephyr and its subsystems, primarily in the areas of string
9manipulation and display.
10
11It is very low footprint and is suitable for projects that do not rely on less
12frequently used portions of the ISO C standard library. It can also be used
13with a number of different toolchains.
14
15The minimal libc implementation can be found in :file:`lib/libc/minimal` in the
16main Zephyr tree.
17
18Functions
19*********
20
21The minimal libc implements the minimal subset of the ISO/IEC 9899:2011
22standard C library functions required to meet the needs of the Zephyr kernel,
23as defined by the :ref:`Coding Guidelines Rule A.4
24<coding_guideline_libc_usage_restrictions_in_zephyr_kernel>`.
25
26Formatted Output
27****************
28
29The minimal libc does not implement its own formatted output processor;
30instead, it maps the C standard formatted output functions such as ``printf``
31and ``sprintf`` to the :c:func:`cbprintf` function, which is Zephyr's own
32C99-compatible formatted output implementation.
33
34For more details, refer to the :ref:`Formatted Output <formatted_output>` OS
35service documentation.
36
37Dynamic Memory Management
38*************************
39
40The minimal libc uses the malloc api family implementation provided by the
41:ref:`common C library <c_library_common>`, which itself is built upon the
42:ref:`kernel memory heap API <heap_v2>`.
43
44Error numbers
45*************
46
47Error numbers are used throughout Zephyr APIs to signal error conditions as
48return values from functions. They are typically returned as the negative value
49of the integer literals defined in this section, and are defined in the
50:file:`errno.h` header file.
51
52A subset of the error numbers defined in the `POSIX errno.h specification`_ and
53other de-facto standard sources have been added to the minimal libc.
54
55A conscious effort is made in Zephyr to keep the values of the minimal libc
56error numbers consistent with the different implementations of the C standard
57libraries supported by Zephyr. The minimal libc :file:`errno.h` is checked
58against that of the :ref:`Newlib <c_library_newlib>` to ensure that the error
59numbers are kept aligned.
60
61Below is a list of the error number definitions. For the actual numeric values
62please refer to `errno.h`_.
63
64.. doxygengroup:: system_errno
65
66.. _`POSIX errno.h specification`: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
67.. _`errno.h`: https://github.com/zephyrproject-rtos/zephyr/blob/main/lib/libc/minimal/include/errno.h
68