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