Sun, 05 Jan 2025 17:31:53 +0100
add new gtk4 listview/combobox implementation
| 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 | /** | |
| 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 | |
| 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 | ||
| 43 | #ifdef __cplusplus | |
| 44 | extern "C" { | |
| 45 | #endif | |
| 46 | ||
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
47 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
48 | /** |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
49 | * The maximum string length that fits into stack memory. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
50 | */ |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
51 | extern unsigned const cx_printf_sbo_size; |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
52 | |
| 174 | 53 | /** |
| 54 | * A \c fprintf like function which writes the output to a stream by | |
| 55 | * using a write_func. | |
| 56 | * | |
| 57 | * @param stream the stream the data is written to | |
| 58 | * @param wfc the write function | |
| 59 | * @param fmt format string | |
| 60 | * @param ... additional arguments | |
| 61 | * @return the total number of bytes written | |
| 62 | */ | |
| 63 | __attribute__((__nonnull__(1, 2, 3), __format__(printf, 3, 4))) | |
| 64 | int cx_fprintf( | |
| 65 | void *stream, | |
| 66 | cx_write_func wfc, | |
| 324 | 67 | const char *fmt, |
| 174 | 68 | ... |
| 69 | ); | |
| 70 | ||
| 71 | /** | |
| 72 | * A \c vfprintf like function which writes the output to a stream by | |
| 73 | * using a write_func. | |
| 74 | * | |
| 75 | * @param stream the stream the data is written to | |
| 76 | * @param wfc the write function | |
| 77 | * @param fmt format string | |
| 78 | * @param ap argument list | |
| 79 | * @return the total number of bytes written | |
| 80 | * @see cx_fprintf() | |
| 81 | */ | |
| 82 | __attribute__((__nonnull__)) | |
| 83 | int cx_vfprintf( | |
| 84 | void *stream, | |
| 85 | cx_write_func wfc, | |
| 324 | 86 | const char *fmt, |
| 174 | 87 | va_list ap |
| 88 | ); | |
| 89 | ||
| 90 | /** | |
| 91 | * A \c asprintf like function which allocates space for a string | |
| 92 | * the result is written to. | |
| 93 | * | |
| 94 | * \note The resulting string is guaranteed to be zero-terminated. | |
| 95 | * | |
| 96 | * @param allocator the CxAllocator used for allocating the string | |
| 97 | * @param fmt format string | |
| 98 | * @param ... additional arguments | |
| 99 | * @return the formatted string | |
| 100 | * @see cx_strfree_a() | |
| 101 | */ | |
| 102 | __attribute__((__nonnull__(1, 2), __format__(printf, 2, 3))) | |
| 103 | cxmutstr cx_asprintf_a( | |
| 324 | 104 | const CxAllocator *allocator, |
| 105 | const char *fmt, | |
| 174 | 106 | ... |
| 107 | ); | |
| 108 | ||
| 109 | /** | |
| 110 | * A \c asprintf like function which allocates space for a string | |
| 111 | * the result is written to. | |
| 112 | * | |
| 113 | * \note The resulting string is guaranteed to be zero-terminated. | |
| 114 | * | |
| 115 | * @param fmt format string | |
| 116 | * @param ... additional arguments | |
| 117 | * @return the formatted string | |
| 118 | * @see cx_strfree() | |
| 119 | */ | |
| 120 | #define cx_asprintf(fmt, ...) \ | |
| 121 | cx_asprintf_a(cxDefaultAllocator, fmt, __VA_ARGS__) | |
| 122 | ||
| 123 | /** | |
| 124 | * A \c vasprintf like function which allocates space for a string | |
| 125 | * the result is written to. | |
| 126 | * | |
| 127 | * \note The resulting string is guaranteed to be zero-terminated. | |
| 128 | * | |
| 129 | * @param allocator the CxAllocator used for allocating the string | |
| 130 | * @param fmt format string | |
| 131 | * @param ap argument list | |
| 132 | * @return the formatted string | |
| 133 | * @see cx_asprintf_a() | |
| 134 | */ | |
| 135 | __attribute__((__nonnull__)) | |
| 136 | cxmutstr cx_vasprintf_a( | |
| 324 | 137 | const CxAllocator *allocator, |
| 138 | const char *fmt, | |
| 174 | 139 | va_list ap |
| 140 | ); | |
| 141 | ||
| 142 | /** | |
| 143 | * A \c vasprintf like function which allocates space for a string | |
| 144 | * the result is written to. | |
| 145 | * | |
| 146 | * \note The resulting string is guaranteed to be zero-terminated. | |
| 147 | * | |
| 148 | * @param fmt format string | |
| 149 | * @param ap argument list | |
| 150 | * @return the formatted string | |
| 151 | * @see cx_asprintf() | |
| 152 | */ | |
| 153 | #define cx_vasprintf(fmt, ap) cx_vasprintf_a(cxDefaultAllocator, fmt, ap) | |
| 154 | ||
| 155 | /** | |
| 156 | * A \c printf like function which writes the output to a CxBuffer. | |
| 157 | * | |
| 158 | * @param buffer a pointer to the buffer the data is written to | |
| 159 | * @param fmt the format string | |
| 160 | * @param ... additional arguments | |
| 161 | * @return the total number of bytes written | |
| 162 | * @see ucx_fprintf() | |
| 163 | */ | |
| 164 | #define cx_bprintf(buffer, fmt, ...) cx_fprintf((CxBuffer*)buffer, \ | |
| 165 | (cx_write_func) cxBufferWrite, fmt, __VA_ARGS__) | |
| 166 | ||
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
167 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
168 | /** |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
169 | * An \c sprintf like function which reallocates the string when the buffer is not large enough. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
170 | * |
| 324 | 171 | * The size of the buffer will be updated in \p len when necessary. |
| 172 | * | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
173 | * \note The resulting string is guaranteed to be zero-terminated. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
174 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
175 | * @param str a pointer to the string buffer |
| 324 | 176 | * @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
|
177 | * @param fmt the format string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
178 | * @param ... additional arguments |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
179 | * @return the length of produced string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
180 | */ |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
181 | #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
|
182 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
183 | /** |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
184 | * An \c sprintf like function which reallocates the string when the buffer is not large enough. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
185 | * |
| 324 | 186 | * The size of the buffer will be updated in \p len when necessary. |
| 187 | * | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
188 | * \note The resulting string is guaranteed to be zero-terminated. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
189 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
190 | * \attention The original buffer MUST have been allocated with the same allocator! |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
191 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
192 | * @param alloc the allocator to use |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
193 | * @param str a pointer to the string buffer |
| 324 | 194 | * @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
|
195 | * @param fmt the format string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
196 | * @param ... additional arguments |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
197 | * @return the length of produced string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
198 | */ |
| 324 | 199 | __attribute__((__nonnull__(1, 2, 3, 4), __format__(printf, 4, 5))) |
| 200 | int cx_sprintf_a(CxAllocator *alloc, char **str, size_t *len, const char *fmt, ... ); | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
201 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
202 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
203 | /** |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
204 | * An \c sprintf like function which reallocates the string when the buffer is not large enough. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
205 | * |
| 324 | 206 | * The size of the buffer will be updated in \p len when necessary. |
| 207 | * | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
208 | * \note The resulting string is guaranteed to be zero-terminated. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
209 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
210 | * @param str a pointer to the string buffer |
| 324 | 211 | * @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
|
212 | * @param fmt the format string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
213 | * @param ap argument list |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
214 | * @return the length of produced string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
215 | */ |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
216 | #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
|
217 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
218 | /** |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
219 | * An \c sprintf like function which reallocates the string when the buffer is not large enough. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
220 | * |
| 324 | 221 | * The size of the buffer will be updated in \p len when necessary. |
| 222 | * | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
223 | * \note The resulting string is guaranteed to be zero-terminated. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
224 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
225 | * \attention The original buffer MUST have been allocated with the same allocator! |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
226 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
227 | * @param alloc the allocator to use |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
228 | * @param str a pointer to the string buffer |
| 324 | 229 | * @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
|
230 | * @param fmt the format string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
231 | * @param ap argument list |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
232 | * @return the length of produced string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
233 | */ |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
234 | __attribute__((__nonnull__)) |
| 324 | 235 | int cx_vsprintf_a(CxAllocator *alloc, char **str, size_t *len, const char *fmt, va_list ap); |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
236 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
237 | |
|
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 | * An \c sprintf like function which allocates a new string when the buffer is not large enough. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
240 | * |
| 324 | 241 | * The size of the buffer will be updated in \p len when necessary. |
| 242 | * | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
243 | * The location of the resulting string will \em always be stored to \p str. When the buffer |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
244 | * was sufficiently large, \p buf itself will be stored to the location of \p str. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
245 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
246 | * \note The resulting string is guaranteed to be zero-terminated. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
247 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
248 | * \remark When a new string needed to be allocated, the contents of \p buf will be |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
249 | * poisoned after the call, because this function tries to produce the string in \p buf, first. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
250 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
251 | * @param buf a pointer to the buffer |
| 324 | 252 | * @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
|
253 | * @param str a pointer to the location |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
254 | * @param fmt the format string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
255 | * @param ... additional arguments |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
256 | * @return the length of produced string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
257 | */ |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
258 | #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
|
259 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
260 | /** |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
261 | * An \c sprintf like function which allocates a new string when the buffer is not large enough. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
262 | * |
| 324 | 263 | * The size of the buffer will be updated in \p len when necessary. |
| 264 | * | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
265 | * The location of the resulting string will \em always be stored to \p str. When the buffer |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
266 | * was sufficiently large, \p buf itself will be stored to the location of \p str. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
267 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
268 | * \note The resulting string is guaranteed to be zero-terminated. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
269 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
270 | * \remark When a new string needed to be allocated, the contents of \p buf will be |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
271 | * poisoned after the call, because this function tries to produce the string in \p buf, first. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
272 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
273 | * @param alloc the allocator to use |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
274 | * @param buf a pointer to the buffer |
| 324 | 275 | * @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
|
276 | * @param str a pointer to the location |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
277 | * @param fmt the format string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
278 | * @param ... additional arguments |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
279 | * @return the length of produced string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
280 | */ |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
281 | __attribute__((__nonnull__(1, 2, 4, 5), __format__(printf, 5, 6))) |
| 324 | 282 | int cx_sprintf_sa(CxAllocator *alloc, char *buf, size_t *len, char **str, const char *fmt, ... ); |
|
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 | * An \c sprintf like function which allocates a new string when the buffer is not large enough. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
286 | * |
| 324 | 287 | * The size of the buffer will be updated in \p len when necessary. |
| 288 | * | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
289 | * The location of the resulting string will \em always be stored to \p str. When the buffer |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
290 | * was sufficiently large, \p buf itself will be stored to the location of \p str. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
291 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
292 | * \note The resulting string is guaranteed to be zero-terminated. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
293 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
294 | * \remark When a new string needed to be allocated, the contents of \p buf will be |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
295 | * poisoned after the call, because this function tries to produce the string in \p buf, first. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
296 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
297 | * @param buf a pointer to the buffer |
| 324 | 298 | * @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
|
299 | * @param str a pointer to the location |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
300 | * @param fmt the format string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
301 | * @param ap argument list |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
302 | * @return the length of produced string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
303 | */ |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
304 | #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
|
305 | |
|
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 | * An \c sprintf like function which allocates a new string when the buffer is not large enough. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
308 | * |
| 324 | 309 | * The size of the buffer will be updated in \p len when necessary. |
| 310 | * | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
311 | * The location of the resulting string will \em always be stored to \p str. When the buffer |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
312 | * was sufficiently large, \p buf itself will be stored to the location of \p str. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
313 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
314 | * \note The resulting string is guaranteed to be zero-terminated. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
315 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
316 | * \remark When a new string needed to be allocated, the contents of \p buf will be |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
317 | * poisoned after the call, because this function tries to produce the string in \p buf, first. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
318 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
319 | * @param alloc the allocator to use |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
320 | * @param buf a pointer to the buffer |
| 324 | 321 | * @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
|
322 | * @param str a pointer to the location |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
323 | * @param fmt the format string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
324 | * @param ap argument list |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
325 | * @return the length of produced string |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
326 | */ |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
327 | __attribute__((__nonnull__)) |
| 324 | 328 | int cx_vsprintf_sa(CxAllocator *alloc, char *buf, size_t *len, char **str, const char *fmt, va_list ap); |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
329 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
330 | |
| 174 | 331 | #ifdef __cplusplus |
| 332 | } // extern "C" | |
| 333 | #endif | |
| 334 | ||
| 335 | #endif //UCX_PRINTF_H |