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