Line data Source code
1 : #pragma once 2 : 3 : #include "platform/config.h" 4 : #include "platform/estdint.h" 5 : 6 : #include <cstddef> 7 : #include <stdarg.h> 8 : 9 : #ifdef __cplusplus 10 : extern "C" 11 : { 12 : #endif 13 : 14 : #define is_digit(c) (((c) >= '0') && ((c) <= '9')) 15 : 16 : #define ZEROPAD 1 /* pad with zero */ 17 : #define SIGN 2 /* unsigned/signed long */ 18 : #define PLUS 4 /* show plus */ 19 : #define SPACE 8 /* space if plus */ 20 : #define LEFT 16 /* left justified */ 21 : #define SPECIAL 32 /* 0x */ 22 : #define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ 23 : 24 : #define do_div(n, base) do_div_hlp(&(n), (base)) 25 : 26 : #if defined(__DCC__) 27 : // clang-format off 28 : #pragma inline do_div_hlp 29 : // clang-format on 30 : #endif 31 0 : ESR_UNUSED static int do_div_hlp(unsigned long* const n, int const base) 32 : { 33 0 : int const res = (int)(*n % (unsigned long)base); 34 : 35 0 : *n = *n / (unsigned long)base; 36 : 37 0 : return res; 38 : } 39 : 40 : /** 41 : * 42 : * \brief Print to the supplied buffer. 43 : * 44 : * This function formats the optional arguments according to the 45 : * printf()-like format string \a fmt and stores the resulting string in 46 : * buffer \a buf. 47 : * 48 : * \param buf Buffer to store string in. (IN) 49 : * \param fmt printf()-like format string. (IN) 50 : * 51 : * \return Length of the resulting string. 52 : * 53 : */ 54 : extern int sprintf(char* buf, char const* fmt, ...); 55 : 56 : /** 57 : * 58 : * \brief Print to the supplied buffer. 59 : * 60 : * This function formats the optional arguments according to the 61 : * printf()-like format string \a fmt and stores the resulting string in 62 : * buffer \a buf. 63 : * 64 : * \param buf Buffer to store string in. (IN) 65 : * \param maxsize max Size from buf 66 : * \param fmt printf()-like format string. (IN) 67 : * 68 : * \return Length of the resulting string. 69 : * 70 : */ 71 : extern int snprintf(char* buf, size_t const maxsize, char const* fmt, ...); 72 : 73 : /** 74 : * 75 : * \brief Print to the supplied buffer. 76 : * 77 : * This function formats the arguments \a args according to the 78 : * printf()-like format string \a fmt and stores the resulting string in 79 : * buffer \a buf. 80 : * 81 : * \param buf Buffer to store string in. (IN) 82 : * \param fmt printf()-like format string. (IN) 83 : * \param args Arguments to format. (IN) 84 : * 85 : * \return Length of the resulting string. 86 : * 87 : */ 88 : extern int vsprintf(char* buf, char const* fmt, va_list args); 89 : 90 : /** 91 : * 92 : * \brief Print to the supplied buffer. 93 : * 94 : * This function formats the arguments \a args according to the 95 : * printf()-like format string \a fmt and stores the resulting string in 96 : * buffer \a buf. 97 : * 98 : * \param buf Buffer to store string in. (IN) 99 : * \param maxsize max Size from buf* * 100 : * \param fmt printf()-like format string. (IN) 101 : * \param args Arguments to format. (IN) 102 : * 103 : * \return Length of the resulting string. 104 : * 105 : */ 106 : extern int vsnprintf(char* buf, size_t const maxsize, char const* fmt, va_list args); 107 : 108 : #ifdef __cplusplus 109 : } 110 : #endif