src/cx/printf.h

changeset 1424
563033aa998c
parent 1285
7acbaa74fbd0
equal deleted inserted replaced
1423:9a72258446cd 1424:563033aa998c
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 /** 28 /**
29 * @file printf.h 29 * @file printf.h
30 * @brief Wrapper for write functions with a printf-like interface. 30 * @brief Wrapper for write-functions with a printf-like interface.
31 * @author Mike Becker 31 * @author Mike Becker
32 * @author Olaf Wintermann 32 * @author Olaf Wintermann
33 * @copyright 2-Clause BSD License 33 * @copyright 2-Clause BSD License
34 */ 34 */
35 35
100 const char *fmt, 100 const char *fmt,
101 va_list ap 101 va_list ap
102 ); 102 );
103 103
104 /** 104 /**
105 * A @c asprintf like function which allocates space for a string 105 * An @c asprintf like function which allocates space for a string
106 * the result is written to. 106 * the result is written to.
107 * 107 *
108 * @note The resulting string is guaranteed to be zero-terminated, 108 * @note The resulting string is guaranteed to be zero-terminated,
109 * unless there was an error, in which case the string's pointer 109 * unless there was an error, in which case the string's pointer
110 * will be @c NULL. 110 * will be @c NULL.
124 const char *fmt, 124 const char *fmt,
125 ... 125 ...
126 ); 126 );
127 127
128 /** 128 /**
129 * A @c asprintf like function which allocates space for a string 129 * An @c asprintf like function which allocates space for a string
130 * the result is written to. 130 * the result is written to.
131 * 131 *
132 * @note The resulting string is guaranteed to be zero-terminated, 132 * @note The resulting string is guaranteed to be zero-terminated,
133 * unless there was an error, in which case the string's pointer 133 * unless there was an error, in which case the string's pointer
134 * will be @c NULL. 134 * will be @c NULL.
167 /** 167 /**
168 * A @c vasprintf like function which allocates space for a string 168 * A @c vasprintf like function which allocates space for a string
169 * the result is written to. 169 * the result is written to.
170 * 170 *
171 * @note The resulting string is guaranteed to be zero-terminated, 171 * @note The resulting string is guaranteed to be zero-terminated,
172 * unless there was in error, in which case the string's pointer 172 * unless there was an error, in which case the string's pointer
173 * will be @c NULL. 173 * will be @c NULL.
174 * 174 *
175 * @param fmt (@c char*) format string 175 * @param fmt (@c char*) format string
176 * @param ap (@c va_list) argument list 176 * @param ap (@c va_list) argument list
177 * @return (@c cxmutstr) the formatted string 177 * @return (@c cxmutstr) the formatted string
202 * 202 *
203 * @param str (@c char**) a pointer to the string buffer 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 204 * @param len (@c size_t*) a pointer to the length of the buffer
205 * @param fmt (@c char*) the format string 205 * @param fmt (@c char*) the format string
206 * @param ... additional arguments 206 * @param ... additional arguments
207 * @return (@c int) the length of produced string or an error code from stdlib printf implementation 207 * @return (@c int) the length of the produced string or an error code from stdlib printf implementation
208 */ 208 */
209 #define cx_sprintf(str, len, fmt, ...) cx_sprintf_a(cxDefaultAllocator, str, len, fmt, __VA_ARGS__) 209 #define cx_sprintf(str, len, fmt, ...) cx_sprintf_a(cxDefaultAllocator, str, len, fmt, __VA_ARGS__)
210 210
211 /** 211 /**
212 * An @c sprintf like function which reallocates the string when the buffer is not large enough. 212 * An @c sprintf like function which reallocates the string when the buffer is not large enough.
220 * @param alloc the allocator to use 220 * @param alloc the allocator to use
221 * @param str a pointer to the string buffer 221 * @param str a pointer to the string buffer
222 * @param len a pointer to the length of the buffer 222 * @param len a pointer to the length of the buffer
223 * @param fmt the format string 223 * @param fmt the format string
224 * @param ... additional arguments 224 * @param ... additional arguments
225 * @return the length of produced string or an error code from stdlib printf implementation 225 * @return the length of the produced string or an error code from stdlib printf implementation
226 */ 226 */
227 cx_attr_nonnull_arg(1, 2, 3, 4) 227 cx_attr_nonnull_arg(1, 2, 3, 4)
228 cx_attr_printf(4, 5) 228 cx_attr_printf(4, 5)
229 cx_attr_cstr_arg(4) 229 cx_attr_cstr_arg(4)
230 cx_attr_export 230 cx_attr_export
246 * 246 *
247 * @param str (@c char**) a pointer to the string buffer 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 248 * @param len (@c size_t*) a pointer to the length of the buffer
249 * @param fmt (@c char*) the format string 249 * @param fmt (@c char*) the format string
250 * @param ap (@c va_list) argument list 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 251 * @return (@c int) the length of the produced string or an error code from stdlib printf implementation
252 */ 252 */
253 #define cx_vsprintf(str, len, fmt, ap) cx_vsprintf_a(cxDefaultAllocator, str, len, fmt, ap) 253 #define cx_vsprintf(str, len, fmt, ap) cx_vsprintf_a(cxDefaultAllocator, str, len, fmt, ap)
254 254
255 /** 255 /**
256 * An @c sprintf like function which reallocates the string when the buffer is not large enough. 256 * An @c sprintf like function which reallocates the string when the buffer is not large enough.
264 * @param alloc the allocator to use 264 * @param alloc the allocator to use
265 * @param str a pointer to the string buffer 265 * @param str a pointer to the string buffer
266 * @param len a pointer to the length of the buffer 266 * @param len a pointer to the length of the buffer
267 * @param fmt the format string 267 * @param fmt the format string
268 * @param ap argument list 268 * @param ap argument list
269 * @return the length of produced string or an error code from stdlib printf implementation 269 * @return the length of the produced string or an error code from stdlib printf implementation
270 */ 270 */
271 cx_attr_nonnull 271 cx_attr_nonnull
272 cx_attr_cstr_arg(4) 272 cx_attr_cstr_arg(4)
273 cx_attr_access_rw(2) 273 cx_attr_access_rw(2)
274 cx_attr_access_rw(3) 274 cx_attr_access_rw(3)
298 * @param buf (@c char*) a pointer to the buffer 298 * @param buf (@c char*) a pointer to the buffer
299 * @param len (@c size_t*) a pointer to the length of 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 300 * @param str (@c char**) a pointer where the location of the result shall be stored
301 * @param fmt (@c char*) the format string 301 * @param fmt (@c char*) the format string
302 * @param ... additional arguments 302 * @param ... additional arguments
303 * @return (@c int) the length of produced string or an error code from stdlib printf implementation 303 * @return (@c int) the length of the produced string or an error code from stdlib printf implementation
304 */ 304 */
305 #define cx_sprintf_s(buf, len, str, fmt, ...) cx_sprintf_sa(cxDefaultAllocator, buf, len, str, fmt, __VA_ARGS__) 305 #define cx_sprintf_s(buf, len, str, fmt, ...) cx_sprintf_sa(cxDefaultAllocator, buf, len, str, fmt, __VA_ARGS__)
306 306
307 /** 307 /**
308 * An @c sprintf like function which allocates a new string when the buffer is not large enough. 308 * An @c sprintf like function which allocates a new string when the buffer is not large enough.
321 * @param buf a pointer to the buffer 321 * @param buf a pointer to the buffer
322 * @param len a pointer to the length of the buffer 322 * @param len a pointer to the length of the buffer
323 * @param str a pointer where the location of the result shall be stored 323 * @param str a pointer where the location of the result shall be stored
324 * @param fmt the format string 324 * @param fmt the format string
325 * @param ... additional arguments 325 * @param ... additional arguments
326 * @return the length of produced string or an error code from stdlib printf implementation 326 * @return the length of the produced string or an error code from stdlib printf implementation
327 */ 327 */
328 cx_attr_nonnull_arg(1, 2, 4, 5) 328 cx_attr_nonnull_arg(1, 2, 4, 5)
329 cx_attr_printf(5, 6) 329 cx_attr_printf(5, 6)
330 cx_attr_cstr_arg(5) 330 cx_attr_cstr_arg(5)
331 cx_attr_access_rw(2) 331 cx_attr_access_rw(2)
357 * @param buf (@c char*) a pointer to the buffer 357 * @param buf (@c char*) a pointer to the buffer
358 * @param len (@c size_t*) a pointer to the length of 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 359 * @param str (@c char**) a pointer where the location of the result shall be stored
360 * @param fmt (@c char*) the format string 360 * @param fmt (@c char*) the format string
361 * @param ap (@c va_list) argument list 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 362 * @return (@c int) the length of the produced string or an error code from stdlib printf implementation
363 */ 363 */
364 #define cx_vsprintf_s(buf, len, str, fmt, ap) cx_vsprintf_sa(cxDefaultAllocator, buf, len, str, fmt, ap) 364 #define cx_vsprintf_s(buf, len, str, fmt, ap) cx_vsprintf_sa(cxDefaultAllocator, buf, len, str, fmt, ap)
365 365
366 /** 366 /**
367 * An @c sprintf like function which allocates a new string when the buffer is not large enough. 367 * An @c sprintf like function which allocates a new string when the buffer is not large enough.
380 * @param buf a pointer to the buffer 380 * @param buf a pointer to the buffer
381 * @param len a pointer to the length of the buffer 381 * @param len a pointer to the length of the buffer
382 * @param str a pointer where the location of the result shall be stored 382 * @param str a pointer where the location of the result shall be stored
383 * @param fmt the format string 383 * @param fmt the format string
384 * @param ap argument list 384 * @param ap argument list
385 * @return the length of produced string or an error code from stdlib printf implementation 385 * @return the length of the produced string or an error code from stdlib printf implementation
386 */ 386 */
387 cx_attr_nonnull 387 cx_attr_nonnull
388 cx_attr_cstr_arg(5) 388 cx_attr_cstr_arg(5)
389 cx_attr_export 389 cx_attr_export
390 int cx_vsprintf_sa( 390 int cx_vsprintf_sa(

mercurial