3 weeks ago
ucx update + fix doc attach/detach + fix ui_set with unbound values
174 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | /** | |
440 | 29 | * @file printf.h |
30 | * @brief Wrapper for write functions with a printf-like interface. | |
31 | * @author Mike Becker | |
32 | * @author Olaf Wintermann | |
33 | * @copyright 2-Clause BSD License | |
174 | 34 | */ |
35 | ||
36 | #ifndef UCX_PRINTF_H | |
37 | #define UCX_PRINTF_H | |
38 | ||
39 | #include "common.h" | |
40 | #include "string.h" | |
41 | #include <stdarg.h> | |
42 | ||
440 | 43 | /** |
44 | * Attribute for printf-like functions. | |
45 | * @param fmt_idx index of the format string parameter | |
46 | * @param arg_idx index of the first formatting argument | |
47 | */ | |
48 | #define cx_attr_printf(fmt_idx, arg_idx) \ | |
49 | __attribute__((__format__(printf, fmt_idx, arg_idx))) | |
50 | ||
174 | 51 | #ifdef __cplusplus |
52 | extern "C" { | |
53 | #endif | |
54 | ||
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
55 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
56 | /** |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
57 | * The maximum string length that fits into stack memory. |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
58 | */ |
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
59 | cx_attr_export |
440 | 60 | extern const unsigned cx_printf_sbo_size; |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
61 | |
174 | 62 | /** |
440 | 63 | * A @c fprintf like function which writes the output to a stream by |
174 | 64 | * using a write_func. |
65 | * | |
66 | * @param stream the stream the data is written to | |
67 | * @param wfc the write function | |
68 | * @param fmt format string | |
69 | * @param ... additional arguments | |
440 | 70 | * @return the total number of bytes written or an error code from stdlib printf implementation |
174 | 71 | */ |
440 | 72 | cx_attr_nonnull_arg(1, 2, 3) |
73 | cx_attr_printf(3, 4) | |
74 | cx_attr_cstr_arg(3) | |
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
75 | cx_attr_export |
174 | 76 | int cx_fprintf( |
77 | void *stream, | |
78 | cx_write_func wfc, | |
324 | 79 | const char *fmt, |
174 | 80 | ... |
81 | ); | |
82 | ||
83 | /** | |
440 | 84 | * A @c vfprintf like function which writes the output to a stream by |
174 | 85 | * using a write_func. |
86 | * | |
87 | * @param stream the stream the data is written to | |
88 | * @param wfc the write function | |
89 | * @param fmt format string | |
90 | * @param ap argument list | |
440 | 91 | * @return the total number of bytes written or an error code from stdlib printf implementation |
174 | 92 | * @see cx_fprintf() |
93 | */ | |
440 | 94 | cx_attr_nonnull |
95 | cx_attr_cstr_arg(3) | |
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
96 | cx_attr_export |
174 | 97 | int cx_vfprintf( |
98 | void *stream, | |
99 | cx_write_func wfc, | |
324 | 100 | const char *fmt, |
174 | 101 | va_list ap |
102 | ); | |
103 | ||
104 | /** | |
440 | 105 | * A @c asprintf like function which allocates space for a string |
174 | 106 | * the result is written to. |
107 | * | |
440 | 108 | * @note The resulting string is guaranteed to be zero-terminated, |
109 | * unless there was an error, in which case the string's pointer | |
110 | * will be @c NULL. | |
174 | 111 | * |
112 | * @param allocator the CxAllocator used for allocating the string | |
113 | * @param fmt format string | |
114 | * @param ... additional arguments | |
115 | * @return the formatted string | |
116 | * @see cx_strfree_a() | |
117 | */ | |
440 | 118 | cx_attr_nonnull_arg(1, 2) |
119 | cx_attr_printf(2, 3) | |
120 | cx_attr_cstr_arg(2) | |
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
121 | cx_attr_export |
174 | 122 | cxmutstr cx_asprintf_a( |
324 | 123 | const CxAllocator *allocator, |
124 | const char *fmt, | |
174 | 125 | ... |
126 | ); | |
127 | ||
128 | /** | |
440 | 129 | * A @c asprintf like function which allocates space for a string |
174 | 130 | * the result is written to. |
131 | * | |
440 | 132 | * @note The resulting string is guaranteed to be zero-terminated, |
133 | * unless there was an error, in which case the string's pointer | |
134 | * will be @c NULL. | |
174 | 135 | * |
440 | 136 | * @param fmt (@c char*) format string |
174 | 137 | * @param ... additional arguments |
440 | 138 | * @return (@c cxmutstr) the formatted string |
174 | 139 | * @see cx_strfree() |
140 | */ | |
141 | #define cx_asprintf(fmt, ...) \ | |
142 | cx_asprintf_a(cxDefaultAllocator, fmt, __VA_ARGS__) | |
143 | ||
144 | /** | |
440 | 145 | * A @c vasprintf like function which allocates space for a string |
174 | 146 | * the result is written to. |
147 | * | |
440 | 148 | * @note The resulting string is guaranteed to be zero-terminated, |
149 | * unless there was an error, in which case the string's pointer | |
150 | * will be @c NULL. | |
174 | 151 | * |
152 | * @param allocator the CxAllocator used for allocating the string | |
153 | * @param fmt format string | |
154 | * @param ap argument list | |
155 | * @return the formatted string | |
156 | * @see cx_asprintf_a() | |
157 | */ | |
440 | 158 | cx_attr_nonnull |
159 | cx_attr_cstr_arg(2) | |
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
160 | cx_attr_export |
174 | 161 | cxmutstr cx_vasprintf_a( |
324 | 162 | const CxAllocator *allocator, |
163 | const char *fmt, | |
174 | 164 | va_list ap |
165 | ); | |
166 | ||
167 | /** | |
440 | 168 | * A @c vasprintf like function which allocates space for a string |
174 | 169 | * the result is written to. |
170 | * | |
440 | 171 | * @note The resulting string is guaranteed to be zero-terminated, |
172 | * unless there was in error, in which case the string's pointer | |
173 | * will be @c NULL. | |
174 | 174 | * |
440 | 175 | * @param fmt (@c char*) format string |
176 | * @param ap (@c va_list) argument list | |
177 | * @return (@c cxmutstr) the formatted string | |
174 | 178 | * @see cx_asprintf() |
179 | */ | |
180 | #define cx_vasprintf(fmt, ap) cx_vasprintf_a(cxDefaultAllocator, fmt, ap) | |
181 | ||
182 | /** | |
440 | 183 | * A @c printf like function which writes the output to a CxBuffer. |
174 | 184 | * |
440 | 185 | * @param buffer (@c CxBuffer*) a pointer to the buffer the data is written to |
186 | * @param fmt (@c char*) the format string | |
174 | 187 | * @param ... additional arguments |
440 | 188 | * @return (@c int) the total number of bytes written or an error code from stdlib printf implementation |
189 | * @see cx_fprintf() | |
190 | * @see cxBufferWrite() | |
174 | 191 | */ |
440 | 192 | #define cx_bprintf(buffer, fmt, ...) cx_fprintf((void*)buffer, \ |
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
193 | cxBufferWriteFunc, fmt, __VA_ARGS__) |
174 | 194 | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
195 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
196 | /** |
440 | 197 | * An @c sprintf like function which reallocates the string when the buffer is not large enough. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
198 | * |
440 | 199 | * The size of the buffer will be updated in @p len when necessary. |
324 | 200 | * |
440 | 201 | * @note The resulting string, if successful, is guaranteed to be zero-terminated. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
202 | * |
440 | 203 | * @param str (@c char**) a pointer to the string buffer |
204 | * @param len (@c size_t*) a pointer to the length of the buffer | |
205 | * @param fmt (@c char*) the format string | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
206 | * @param ... additional arguments |
440 | 207 | * @return (@c int) the length of produced string or an error code from stdlib printf implementation |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
208 | */ |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
209 | #define cx_sprintf(str, len, fmt, ...) cx_sprintf_a(cxDefaultAllocator, str, len, fmt, __VA_ARGS__) |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
210 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
211 | /** |
440 | 212 | * An @c sprintf like function which reallocates the string when the buffer is not large enough. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
213 | * |
440 | 214 | * The size of the buffer will be updated in @p len when necessary. |
324 | 215 | * |
440 | 216 | * @note The resulting string, if successful, is guaranteed to be zero-terminated. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
217 | * |
440 | 218 | * @attention The original buffer MUST have been allocated with the same allocator! |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
219 | * |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
220 | * @param alloc the allocator to use |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
221 | * @param str a pointer to the string buffer |
324 | 222 | * @param len a pointer to the length of the buffer |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
223 | * @param fmt the format string |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
224 | * @param ... additional arguments |
440 | 225 | * @return the length of produced string or an error code from stdlib printf implementation |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
226 | */ |
440 | 227 | cx_attr_nonnull_arg(1, 2, 3, 4) |
228 | cx_attr_printf(4, 5) | |
229 | cx_attr_cstr_arg(4) | |
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
230 | cx_attr_export |
440 | 231 | int cx_sprintf_a( |
232 | CxAllocator *alloc, | |
233 | char **str, | |
234 | size_t *len, | |
235 | const char *fmt, | |
236 | ... | |
237 | ); | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
238 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
239 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
240 | /** |
440 | 241 | * An @c sprintf like function which reallocates the string when the buffer is not large enough. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
242 | * |
440 | 243 | * The size of the buffer will be updated in @p len when necessary. |
324 | 244 | * |
440 | 245 | * @note The resulting string, if successful, is guaranteed to be zero-terminated. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
246 | * |
440 | 247 | * @param str (@c char**) a pointer to the string buffer |
248 | * @param len (@c size_t*) a pointer to the length of the buffer | |
249 | * @param fmt (@c char*) the format string | |
250 | * @param ap (@c va_list) argument list | |
251 | * @return (@c int) the length of produced string or an error code from stdlib printf implementation | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
252 | */ |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
253 | #define cx_vsprintf(str, len, fmt, ap) cx_vsprintf_a(cxDefaultAllocator, str, len, fmt, ap) |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
254 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
255 | /** |
440 | 256 | * An @c sprintf like function which reallocates the string when the buffer is not large enough. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
257 | * |
440 | 258 | * The size of the buffer will be updated in @p len when necessary. |
324 | 259 | * |
440 | 260 | * @note The resulting string is guaranteed to be zero-terminated. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
261 | * |
440 | 262 | * @attention The original buffer MUST have been allocated with the same allocator! |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
263 | * |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
264 | * @param alloc the allocator to use |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
265 | * @param str a pointer to the string buffer |
324 | 266 | * @param len a pointer to the length of the buffer |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
267 | * @param fmt the format string |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
268 | * @param ap argument list |
440 | 269 | * @return the length of produced string or an error code from stdlib printf implementation |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
270 | */ |
440 | 271 | cx_attr_nonnull |
272 | cx_attr_cstr_arg(4) | |
273 | cx_attr_access_rw(2) | |
274 | cx_attr_access_rw(3) | |
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
275 | cx_attr_export |
440 | 276 | int cx_vsprintf_a( |
277 | CxAllocator *alloc, | |
278 | char **str, | |
279 | size_t *len, | |
280 | const char *fmt, | |
281 | va_list ap | |
282 | ); | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
283 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
284 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
285 | /** |
440 | 286 | * An @c sprintf like function which allocates a new string when the buffer is not large enough. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
287 | * |
440 | 288 | * The size of the buffer will be updated in @p len when necessary. |
324 | 289 | * |
440 | 290 | * The location of the resulting string will @em always be stored to @p str. When the buffer |
291 | * was sufficiently large, @p buf itself will be stored to the location of @p str. | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
292 | * |
440 | 293 | * @note The resulting string, if successful, is guaranteed to be zero-terminated. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
294 | * |
440 | 295 | * @remark When a new string needed to be allocated, the contents of @p buf will be |
296 | * poisoned after the call, because this function tries to produce the string in @p buf, first. | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
297 | * |
440 | 298 | * @param buf (@c char*) a pointer to the buffer |
299 | * @param len (@c size_t*) a pointer to the length of the buffer | |
300 | * @param str (@c char**) a pointer where the location of the result shall be stored | |
301 | * @param fmt (@c char*) the format string | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
302 | * @param ... additional arguments |
440 | 303 | * @return (@c int) the length of produced string or an error code from stdlib printf implementation |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
304 | */ |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
305 | #define cx_sprintf_s(buf, len, str, fmt, ...) cx_sprintf_sa(cxDefaultAllocator, buf, len, str, fmt, __VA_ARGS__) |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
306 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
307 | /** |
440 | 308 | * An @c sprintf like function which allocates a new string when the buffer is not large enough. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
309 | * |
440 | 310 | * The size of the buffer will be updated in @p len when necessary. |
324 | 311 | * |
440 | 312 | * The location of the resulting string will @em always be stored to @p str. When the buffer |
313 | * was sufficiently large, @p buf itself will be stored to the location of @p str. | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
314 | * |
440 | 315 | * @note The resulting string, if successful, is guaranteed to be zero-terminated. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
316 | * |
440 | 317 | * @remark When a new string needed to be allocated, the contents of @p buf will be |
318 | * poisoned after the call, because this function tries to produce the string in @p buf, first. | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
319 | * |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
320 | * @param alloc the allocator to use |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
321 | * @param buf a pointer to the buffer |
324 | 322 | * @param len a pointer to the length of the buffer |
440 | 323 | * @param str a pointer where the location of the result shall be stored |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
324 | * @param fmt the format string |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
325 | * @param ... additional arguments |
440 | 326 | * @return the length of produced string or an error code from stdlib printf implementation |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
327 | */ |
440 | 328 | cx_attr_nonnull_arg(1, 2, 4, 5) |
329 | cx_attr_printf(5, 6) | |
330 | cx_attr_cstr_arg(5) | |
331 | cx_attr_access_rw(2) | |
332 | cx_attr_access_rw(3) | |
333 | cx_attr_access_rw(4) | |
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
334 | cx_attr_export |
440 | 335 | int cx_sprintf_sa( |
336 | CxAllocator *alloc, | |
337 | char *buf, | |
338 | size_t *len, | |
339 | char **str, | |
340 | const char *fmt, | |
341 | ... | |
342 | ); | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
343 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
344 | /** |
440 | 345 | * An @c sprintf like function which allocates a new string when the buffer is not large enough. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
346 | * |
440 | 347 | * The size of the buffer will be updated in @p len when necessary. |
324 | 348 | * |
440 | 349 | * The location of the resulting string will @em always be stored to @p str. When the buffer |
350 | * was sufficiently large, @p buf itself will be stored to the location of @p str. | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
351 | * |
440 | 352 | * @note The resulting string is guaranteed to be zero-terminated. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
353 | * |
440 | 354 | * @remark When a new string needed to be allocated, the contents of @p buf will be |
355 | * poisoned after the call, because this function tries to produce the string in @p buf, first. | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
356 | * |
440 | 357 | * @param buf (@c char*) a pointer to the buffer |
358 | * @param len (@c size_t*) a pointer to the length of the buffer | |
359 | * @param str (@c char**) a pointer where the location of the result shall be stored | |
360 | * @param fmt (@c char*) the format string | |
361 | * @param ap (@c va_list) argument list | |
362 | * @return (@c int) the length of produced string or an error code from stdlib printf implementation | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
363 | */ |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
364 | #define cx_vsprintf_s(buf, len, str, fmt, ap) cx_vsprintf_sa(cxDefaultAllocator, buf, len, str, fmt, ap) |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
365 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
366 | /** |
440 | 367 | * An @c sprintf like function which allocates a new string when the buffer is not large enough. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
368 | * |
440 | 369 | * The size of the buffer will be updated in @p len when necessary. |
324 | 370 | * |
440 | 371 | * The location of the resulting string will @em always be stored to @p str. When the buffer |
372 | * was sufficiently large, @p buf itself will be stored to the location of @p str. | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
373 | * |
440 | 374 | * @note The resulting string is guaranteed to be zero-terminated. |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
375 | * |
440 | 376 | * @remark When a new string needed to be allocated, the contents of @p buf will be |
377 | * poisoned after the call, because this function tries to produce the string in @p buf, first. | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
378 | * |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
379 | * @param alloc the allocator to use |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
380 | * @param buf a pointer to the buffer |
324 | 381 | * @param len a pointer to the length of the buffer |
440 | 382 | * @param str a pointer where the location of the result shall be stored |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
383 | * @param fmt the format string |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
384 | * @param ap argument list |
440 | 385 | * @return the length of produced string or an error code from stdlib printf implementation |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
386 | */ |
440 | 387 | cx_attr_nonnull |
388 | cx_attr_cstr_arg(5) | |
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
389 | cx_attr_export |
440 | 390 | int cx_vsprintf_sa( |
391 | CxAllocator *alloc, | |
392 | char *buf, | |
393 | size_t *len, | |
394 | char **str, | |
395 | const char *fmt, | |
396 | va_list ap | |
397 | ); | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
398 | |
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
399 | |
174 | 400 | #ifdef __cplusplus |
401 | } // extern "C" | |
402 | #endif | |
403 | ||
404 | #endif //UCX_PRINTF_H |