Mon, 13 Oct 2025 21:31:58 +0200
update ucx
| 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 | /** | |
| 440 | 30 | * @file buffer.h |
| 174 | 31 | * |
| 440 | 32 | * @brief Advanced buffer implementation. |
| 174 | 33 | * |
| 34 | * Instances of CxBuffer can be used to read from or to write to like one | |
| 35 | * would do with a stream. | |
| 36 | * | |
| 37 | * Some features for convenient use of the buffer | |
| 38 | * can be enabled. See the documentation of the macro constants for more | |
| 39 | * information. | |
| 40 | * | |
| 440 | 41 | * @author Mike Becker |
| 42 | * @author Olaf Wintermann | |
| 43 | * @copyright 2-Clause BSD License | |
| 174 | 44 | */ |
| 45 | ||
| 46 | #ifndef UCX_BUFFER_H | |
| 47 | #define UCX_BUFFER_H | |
| 48 | ||
| 49 | #include "common.h" | |
| 50 | #include "allocator.h" | |
| 51 | ||
| 440 | 52 | #ifdef __cplusplus |
| 174 | 53 | extern "C" { |
| 54 | #endif | |
| 55 | ||
| 56 | /** | |
| 57 | * No buffer features enabled (all flags cleared). | |
| 58 | */ | |
| 59 | #define CX_BUFFER_DEFAULT 0x00 | |
| 60 | ||
| 61 | /** | |
| 62 | * If this flag is enabled, the buffer will automatically free its contents when destroyed. | |
| 440 | 63 | * |
| 64 | * Do NOT set this flag together with #CX_BUFFER_COPY_ON_WRITE. It will be automatically | |
| 845 | 65 | * set when the copy-on-write operation is performed. |
| 174 | 66 | */ |
| 67 | #define CX_BUFFER_FREE_CONTENTS 0x01 | |
| 68 | ||
| 69 | /** | |
| 440 | 70 | * If this flag is enabled, the buffer will automatically extend its capacity. |
| 174 | 71 | */ |
| 72 | #define CX_BUFFER_AUTO_EXTEND 0x02 | |
| 73 | ||
| 440 | 74 | /** |
| 75 | * If this flag is enabled, the buffer will allocate new memory when written to. | |
| 76 | * | |
| 845 | 77 | * The current contents of the buffer will be copied to the new memory, and the flag |
| 440 | 78 | * will be cleared while the #CX_BUFFER_FREE_CONTENTS flag will be set automatically. |
| 79 | */ | |
| 80 | #define CX_BUFFER_COPY_ON_WRITE 0x04 | |
| 81 | ||
| 82 | /** | |
| 83 | * If this flag is enabled, the buffer will copy its contents to a new memory area on reallocation. | |
| 84 | * | |
| 85 | * After performing the copy, the flag is automatically cleared. | |
| 86 | * This flag has no effect on buffers which do not have #CX_BUFFER_AUTO_EXTEND set, which is why | |
| 87 | * buffers automatically admit the auto-extend flag when initialized with copy-on-extend enabled. | |
| 88 | */ | |
| 89 | #define CX_BUFFER_COPY_ON_EXTEND 0x08 | |
| 90 | ||
| 91 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
92 | * Function pointer for cxBufferWrite that is compatible with cx_write_func. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
93 | * @see cx_write_func |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
94 | */ |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
95 | #define cxBufferWriteFunc ((cx_write_func) cxBufferWrite) |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
96 | /** |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
97 | * Function pointer for cxBufferRead that is compatible with cx_read_func. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
98 | * @see cx_read_func |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
99 | */ |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
100 | #define cxBufferReadFunc ((cx_read_func) cxBufferRead) |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
101 | |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
102 | /** |
| 440 | 103 | * Configuration for automatic flushing. |
| 104 | */ | |
| 105 | struct cx_buffer_flush_config_s { | |
| 106 | /** | |
| 107 | * The buffer may not extend beyond this threshold before starting to flush. | |
| 108 | * | |
| 109 | * Only used when the buffer uses #CX_BUFFER_AUTO_EXTEND. | |
| 110 | * The threshold will be the maximum capacity the buffer is extended to | |
| 111 | * before flushing. | |
| 112 | */ | |
| 113 | size_t threshold; | |
| 114 | /** | |
| 115 | * The block size for the elements to flush. | |
| 116 | */ | |
| 117 | size_t blksize; | |
| 118 | /** | |
| 119 | * The maximum number of blocks to flush in one cycle. | |
| 120 | * | |
| 121 | * @attention while it is guaranteed that cxBufferFlush() will not flush | |
| 122 | * more blocks, this is not necessarily the case for cxBufferWrite(). | |
| 123 | * After performing a flush cycle, cxBufferWrite() will retry the write | |
| 124 | * operation and potentially trigger another flush cycle, until the | |
| 125 | * flush target accepts no more data. | |
| 126 | */ | |
| 127 | size_t blkmax; | |
| 128 | ||
| 129 | /** | |
| 845 | 130 | * The target for the write function. |
| 440 | 131 | */ |
| 132 | void *target; | |
| 133 | ||
| 134 | /** | |
| 135 | * The write-function used for flushing. | |
| 136 | * If NULL, the flushed content gets discarded. | |
| 137 | */ | |
| 138 | cx_write_func wfunc; | |
| 139 | }; | |
| 140 | ||
| 141 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
142 | * Type alias for the flush configuration struct. |
| 440 | 143 | * |
| 144 | * @code | |
| 145 | * struct cx_buffer_flush_config_s { | |
| 146 | * size_t threshold; | |
| 147 | * size_t blksize; | |
| 148 | * size_t blkmax; | |
| 149 | * void *target; | |
| 150 | * cx_write_func wfunc; | |
| 151 | * }; | |
| 152 | * @endcode | |
| 153 | */ | |
| 154 | typedef struct cx_buffer_flush_config_s CxBufferFlushConfig; | |
| 155 | ||
| 174 | 156 | /** Structure for the UCX buffer data. */ |
| 440 | 157 | struct cx_buffer_s { |
| 174 | 158 | /** A pointer to the buffer contents. */ |
| 159 | union { | |
| 160 | /** | |
| 161 | * Data is interpreted as text. | |
| 162 | */ | |
| 163 | char *space; | |
| 164 | /** | |
| 165 | * Data is interpreted as binary. | |
| 166 | */ | |
| 167 | unsigned char *bytes; | |
| 168 | }; | |
| 169 | /** The allocator to use for automatic memory management. */ | |
| 324 | 170 | const CxAllocator *allocator; |
| 440 | 171 | /** |
| 172 | * Optional flush configuration | |
| 173 | * | |
| 174 | * @see cxBufferEnableFlushing() | |
| 175 | */ | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
176 | CxBufferFlushConfig *flush; |
| 174 | 177 | /** Current position of the buffer. */ |
| 178 | size_t pos; | |
| 179 | /** Current capacity (i.e. maximum size) of the buffer. */ | |
| 180 | size_t capacity; | |
| 181 | /** Current size of the buffer content. */ | |
| 182 | size_t size; | |
| 183 | /** | |
| 184 | * Flag register for buffer features. | |
| 185 | * @see #CX_BUFFER_DEFAULT | |
| 186 | * @see #CX_BUFFER_FREE_CONTENTS | |
| 187 | * @see #CX_BUFFER_AUTO_EXTEND | |
| 440 | 188 | * @see #CX_BUFFER_COPY_ON_WRITE |
| 174 | 189 | */ |
| 190 | int flags; | |
| 440 | 191 | }; |
| 174 | 192 | |
| 193 | /** | |
| 194 | * UCX buffer. | |
| 195 | */ | |
| 440 | 196 | typedef struct cx_buffer_s CxBuffer; |
| 174 | 197 | |
| 198 | /** | |
| 199 | * Initializes a fresh buffer. | |
| 200 | * | |
| 440 | 201 | * You may also provide a read-only @p space, in which case |
| 202 | * you will need to cast the pointer, and you should set the | |
| 203 | * #CX_BUFFER_COPY_ON_WRITE flag. | |
| 204 | * | |
| 845 | 205 | * You need to set the size manually after initialization if |
| 440 | 206 | * you provide @p space which already contains data. |
| 207 | * | |
| 208 | * When you specify stack memory as @p space and decide to use | |
| 209 | * the auto-extension feature, you @em must use the | |
| 210 | * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the | |
| 211 | * #CX_BUFFER_AUTO_EXTEND flag. | |
| 212 | * | |
| 845 | 213 | * @note You may provide @c NULL as the argument for @p space. |
| 174 | 214 | * Then this function will allocate the space and enforce |
| 440 | 215 | * the #CX_BUFFER_FREE_CONTENTS flag. In that case, specifying |
| 216 | * copy-on-write should be avoided, because the allocated | |
| 217 | * space will be leaking after the copy-on-write operation. | |
| 174 | 218 | * |
| 219 | * @param buffer the buffer to initialize | |
| 440 | 220 | * @param space pointer to the memory area, or @c NULL to allocate |
| 174 | 221 | * new memory |
| 222 | * @param capacity the capacity of the buffer | |
| 223 | * @param allocator the allocator this buffer shall use for automatic | |
| 440 | 224 | * memory management |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
225 | * (if @c NULL, the cxDefaultAllocator will be used) |
| 174 | 226 | * @param flags buffer features (see cx_buffer_s.flags) |
| 227 | * @return zero on success, non-zero if a required allocation failed | |
| 228 | */ | |
| 440 | 229 | cx_attr_nonnull_arg(1) |
|
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 |
| 174 | 231 | int cxBufferInit( |
| 232 | CxBuffer *buffer, | |
| 233 | void *space, | |
| 234 | size_t capacity, | |
| 324 | 235 | const CxAllocator *allocator, |
| 174 | 236 | int flags |
| 237 | ); | |
| 238 | ||
| 239 | /** | |
| 440 | 240 | * Configures the buffer for flushing. |
| 174 | 241 | * |
| 440 | 242 | * Flushing can happen automatically when data is written |
| 243 | * to the buffer (see cxBufferWrite()) or manually when | |
| 244 | * cxBufferFlush() is called. | |
| 174 | 245 | * |
| 440 | 246 | * @param buffer the buffer |
| 247 | * @param config the flush configuration | |
| 248 | * @retval zero success | |
| 249 | * @retval non-zero failure | |
| 250 | * @see cxBufferFlush() | |
| 251 | * @see cxBufferWrite() | |
| 174 | 252 | */ |
| 440 | 253 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
254 | cx_attr_export |
| 440 | 255 | int cxBufferEnableFlushing( |
| 256 | CxBuffer *buffer, | |
| 257 | CxBufferFlushConfig config | |
| 174 | 258 | ); |
| 259 | ||
| 260 | /** | |
| 261 | * Destroys the buffer contents. | |
| 262 | * | |
| 263 | * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled. | |
| 264 | * If you want to free the memory of the entire buffer, use cxBufferFree(). | |
| 265 | * | |
| 266 | * @param buffer the buffer which contents shall be destroyed | |
| 267 | * @see cxBufferInit() | |
| 268 | */ | |
| 440 | 269 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
270 | cx_attr_export |
| 174 | 271 | void cxBufferDestroy(CxBuffer *buffer); |
| 272 | ||
| 273 | /** | |
| 274 | * Deallocates the buffer. | |
| 275 | * | |
| 276 | * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, this function also destroys | |
| 440 | 277 | * the contents. If you @em only want to destroy the contents, use cxBufferDestroy(). |
| 278 | * | |
| 174 | 279 | * @param buffer the buffer to deallocate |
| 280 | * @see cxBufferCreate() | |
| 281 | */ | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
282 | cx_attr_export |
| 174 | 283 | void cxBufferFree(CxBuffer *buffer); |
| 284 | ||
| 285 | /** | |
| 440 | 286 | * Allocates and initializes a fresh buffer. |
| 287 | * | |
| 288 | * You may also provide a read-only @p space, in which case | |
| 289 | * you will need to cast the pointer, and you should set the | |
| 290 | * #CX_BUFFER_COPY_ON_WRITE flag. | |
| 291 | * When you specify stack memory as @p space and decide to use | |
| 292 | * the auto-extension feature, you @em must use the | |
| 293 | * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the | |
| 294 | * #CX_BUFFER_AUTO_EXTEND flag. | |
| 295 | * | |
| 845 | 296 | * @note You may provide @c NULL as the argument for @p space. |
| 440 | 297 | * Then this function will allocate the space and enforce |
| 298 | * the #CX_BUFFER_FREE_CONTENTS flag. | |
| 299 | * | |
| 300 | * @param space pointer to the memory area, or @c NULL to allocate | |
| 301 | * new memory | |
| 302 | * @param capacity the capacity of the buffer | |
| 303 | * @param allocator the allocator to use for allocating the structure and the automatic | |
| 304 | * memory management within the buffer | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
305 | * (if @c NULL, the cxDefaultAllocator will be used) |
| 440 | 306 | * @param flags buffer features (see cx_buffer_s.flags) |
| 307 | * @return a pointer to the buffer on success, @c NULL if a required allocation failed | |
| 308 | */ | |
| 309 | cx_attr_malloc | |
| 310 | cx_attr_dealloc(cxBufferFree, 1) | |
| 311 | cx_attr_nodiscard | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
312 | cx_attr_export |
| 440 | 313 | CxBuffer *cxBufferCreate( |
| 314 | void *space, | |
| 315 | size_t capacity, | |
| 316 | const CxAllocator *allocator, | |
| 317 | int flags | |
| 318 | ); | |
| 319 | ||
| 320 | /** | |
| 174 | 321 | * Shifts the contents of the buffer by the given offset. |
| 322 | * | |
| 323 | * If the offset is positive, the contents are shifted to the right. | |
| 324 | * If auto extension is enabled, the buffer grows, if necessary. | |
| 325 | * In case the auto extension fails, this function returns a non-zero value and | |
| 326 | * no contents are changed. | |
| 845 | 327 | * When the auto extension is disabled, the contents that do not fit into the |
| 328 | * buffer are discarded. | |
| 174 | 329 | * |
| 330 | * If the offset is negative, the contents are shifted to the left where the | |
| 440 | 331 | * first @p shift bytes are discarded. |
| 174 | 332 | * The new size of the buffer is the old size minus the absolute shift value. |
| 333 | * If this value is larger than the buffer size, the buffer is emptied (but | |
| 334 | * not cleared, see the security note below). | |
| 335 | * | |
| 845 | 336 | * The buffer position gets shifted alongside the content but is kept |
| 174 | 337 | * within the boundaries of the buffer. |
| 338 | * | |
| 440 | 339 | * @note For situations where @c off_t is not large enough, there are specialized cxBufferShiftLeft() and |
| 845 | 340 | * cxBufferShiftRight() functions using a @c size_t as the parameter type. |
| 174 | 341 | * |
| 440 | 342 | * @attention |
| 343 | * Security Note: The shifting operation does @em not erase the previously occupied memory cells. | |
| 845 | 344 | * But you can do that manually by calling |
| 174 | 345 | * <code>memset(buffer->bytes, 0, shift)</code> for a right shift or |
| 346 | * <code>memset(buffer->bytes + buffer->size, 0, buffer->capacity - buffer->size)</code> | |
| 347 | * for a left shift. | |
| 348 | * | |
| 349 | * @param buffer the buffer | |
| 350 | * @param shift the shift offset (negative means left shift) | |
| 440 | 351 | * @retval zero success |
| 352 | * @retval non-zero if a required auto-extension or copy-on-write fails | |
| 353 | * @see cxBufferShiftLeft() | |
| 354 | * @see cxBufferShiftRight() | |
| 174 | 355 | */ |
| 440 | 356 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
357 | cx_attr_export |
| 174 | 358 | int cxBufferShift( |
| 359 | CxBuffer *buffer, | |
| 360 | off_t shift | |
| 361 | ); | |
| 362 | ||
| 363 | /** | |
| 364 | * Shifts the buffer to the right. | |
| 365 | * See cxBufferShift() for details. | |
| 366 | * | |
| 367 | * @param buffer the buffer | |
| 368 | * @param shift the shift offset | |
| 440 | 369 | * @retval zero success |
| 370 | * @retval non-zero if a required auto-extension or copy-on-write fails | |
| 174 | 371 | * @see cxBufferShift() |
| 372 | */ | |
| 440 | 373 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
374 | cx_attr_export |
| 174 | 375 | int cxBufferShiftRight( |
| 376 | CxBuffer *buffer, | |
| 377 | size_t shift | |
| 378 | ); | |
| 379 | ||
| 380 | /** | |
| 381 | * Shifts the buffer to the left. | |
| 382 | * See cxBufferShift() for details. | |
| 383 | * | |
| 384 | * @param buffer the buffer | |
| 385 | * @param shift the positive shift offset | |
| 440 | 386 | * @retval zero success |
| 387 | * @retval non-zero if the buffer uses copy-on-write and the allocation fails | |
| 174 | 388 | * @see cxBufferShift() |
| 389 | */ | |
| 440 | 390 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
391 | cx_attr_export |
| 174 | 392 | int cxBufferShiftLeft( |
| 393 | CxBuffer *buffer, | |
| 394 | size_t shift | |
| 395 | ); | |
| 396 | ||
| 397 | ||
| 398 | /** | |
| 399 | * Moves the position of the buffer. | |
| 400 | * | |
| 440 | 401 | * The new position is relative to the @p whence argument. |
| 174 | 402 | * |
| 440 | 403 | * @li @c SEEK_SET marks the start of the buffer. |
| 404 | * @li @c SEEK_CUR marks the current position. | |
| 405 | * @li @c SEEK_END marks the end of the buffer. | |
| 174 | 406 | * |
| 407 | * With an offset of zero, this function sets the buffer position to zero | |
| 440 | 408 | * (@c SEEK_SET), the buffer size (@c SEEK_END) or leaves the buffer position |
| 409 | * unchanged (@c SEEK_CUR). | |
| 174 | 410 | * |
| 411 | * @param buffer the buffer | |
| 440 | 412 | * @param offset position offset relative to @p whence |
| 413 | * @param whence one of @c SEEK_SET, @c SEEK_CUR or @c SEEK_END | |
| 414 | * @retval zero success | |
| 415 | * @retval non-zero if the position is invalid | |
| 174 | 416 | * |
| 417 | */ | |
| 440 | 418 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
419 | cx_attr_export |
| 174 | 420 | int cxBufferSeek( |
| 421 | CxBuffer *buffer, | |
| 422 | off_t offset, | |
| 423 | int whence | |
| 424 | ); | |
| 425 | ||
| 426 | /** | |
| 427 | * Clears the buffer by resetting the position and deleting the data. | |
| 428 | * | |
| 429 | * The data is deleted by zeroing it with a call to memset(). | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
430 | * If you do not need that, you can use the faster cxBufferReset(). |
| 174 | 431 | * |
| 440 | 432 | * @note If the #CX_BUFFER_COPY_ON_WRITE flag is set, this function |
| 433 | * will not erase the data and behave exactly as cxBufferReset(). | |
| 434 | * | |
| 174 | 435 | * @param buffer the buffer to be cleared |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
436 | * @see cxBufferReset() |
| 174 | 437 | */ |
| 440 | 438 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
439 | cx_attr_export |
| 174 | 440 | void cxBufferClear(CxBuffer *buffer); |
| 441 | ||
| 442 | /** | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
443 | * Resets the buffer by resetting the position and size to zero. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
444 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
445 | * The data in the buffer is not deleted. If you need a safe |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
446 | * reset of the buffer, use cxBufferClear(). |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
447 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
448 | * @param buffer the buffer to be cleared |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
449 | * @see cxBufferClear() |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
450 | */ |
| 440 | 451 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
452 | cx_attr_export |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
453 | void cxBufferReset(CxBuffer *buffer); |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
454 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
455 | /** |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
456 | * Tests, if the buffer position has exceeded the buffer size. |
| 174 | 457 | * |
| 458 | * @param buffer the buffer to test | |
| 440 | 459 | * @retval true if the current buffer position has exceeded the last |
| 460 | * byte of the buffer's contents | |
| 461 | * @retval false otherwise | |
| 174 | 462 | */ |
| 440 | 463 | cx_attr_nonnull |
| 464 | cx_attr_nodiscard | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
465 | cx_attr_export |
| 440 | 466 | bool cxBufferEof(const CxBuffer *buffer); |
| 174 | 467 | |
| 468 | ||
| 469 | /** | |
| 470 | * Ensures that the buffer has a minimum capacity. | |
| 471 | * | |
| 472 | * If the current capacity is not sufficient, the buffer will be extended. | |
| 473 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
474 | * The new capacity will be a power of two until the system's page size is reached. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
475 | * Then, the new capacity will be a multiple of the page size. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
476 | * |
| 174 | 477 | * @param buffer the buffer |
| 478 | * @param capacity the minimum required capacity for this buffer | |
| 440 | 479 | * @retval zero the capacity was already sufficient or successfully increased |
| 480 | * @retval non-zero on allocation failure | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
481 | * @see cxBufferShrink() |
| 174 | 482 | */ |
| 440 | 483 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
484 | cx_attr_export |
| 174 | 485 | int cxBufferMinimumCapacity( |
| 486 | CxBuffer *buffer, | |
| 487 | size_t capacity | |
| 488 | ); | |
| 489 | ||
| 490 | /** | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
491 | * Shrinks the capacity of the buffer to fit its current size. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
492 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
493 | * If @p reserve is larger than zero, the buffer is shrunk to its size plus |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
494 | * the number of reserved bytes. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
495 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
496 | * If the current capacity is not larger than the size plus the reserved bytes, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
497 | * nothing happens. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
498 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
499 | * If the #CX_BUFFER_COPY_ON_WRITE or #CX_BUFFER_COPY_ON_EXTEND flag is set, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
500 | * this function does nothing. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
501 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
502 | * @param buffer the buffer |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
503 | * @param reserve the number of bytes that shall remain reserved |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
504 | * @see cxBufferMinimumCapacity() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
505 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
506 | cx_attr_nonnull |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
507 | cx_attr_export |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
508 | void cxBufferShrink( |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
509 | CxBuffer *buffer, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
510 | size_t reserve |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
511 | ); |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
512 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
513 | /** |
| 174 | 514 | * Writes data to a CxBuffer. |
| 515 | * | |
| 440 | 516 | * If automatic flushing is not enabled, the data is simply written into the |
| 845 | 517 | * buffer at the current position, and the position of the buffer is increased |
| 440 | 518 | * by the number of bytes written. |
| 519 | * | |
| 174 | 520 | * If flushing is enabled and the buffer needs to flush, the data is flushed to |
| 521 | * the target until the target signals that it cannot take more data by | |
| 522 | * returning zero via the respective write function. In that case, the remaining | |
| 523 | * data in this buffer is shifted to the beginning of this buffer so that the | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
524 | * newly available space can be used to append as much data as possible. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
525 | * |
| 845 | 526 | * This function only stops writing more elements when the flush target and this |
| 174 | 527 | * buffer are both incapable of taking more data or all data has been written. |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
528 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
529 | * If, after flushing, the number of items that shall be written still exceeds |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
530 | * the capacity or flush threshold, this function tries to write all items directly |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
531 | * to the flush target, if possible. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
532 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
533 | * The number returned by this function is the number of elements from |
| 845 | 534 | * @c ptr that could be written to either the flush target or the buffer. |
| 535 | * That means it does @em not include the number of items that were already in | |
| 536 | * the buffer and were also flushed during the process. | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
537 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
538 | * @attention |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
539 | * When @p size is larger than one and the contents of the buffer are not aligned |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
540 | * with @p size, flushing stops after all complete items have been flushed, leaving |
| 845 | 541 | * the misaligned part in the 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
|
542 | * Afterward, this function only writes as many items as possible to the buffer. |
| 174 | 543 | * |
| 440 | 544 | * @note The signature is compatible with the fwrite() family of functions. |
| 174 | 545 | * |
| 546 | * @param ptr a pointer to the memory area containing the bytes to be written | |
| 547 | * @param size the length of one element | |
| 548 | * @param nitems the element count | |
| 549 | * @param buffer the CxBuffer to write to | |
| 550 | * @return the total count of elements written | |
| 440 | 551 | * @see cxBufferAppend() |
| 552 | * @see cxBufferRead() | |
| 174 | 553 | */ |
| 440 | 554 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
555 | cx_attr_export |
| 174 | 556 | size_t cxBufferWrite( |
| 324 | 557 | const void *ptr, |
| 174 | 558 | size_t size, |
| 559 | size_t nitems, | |
| 560 | CxBuffer *buffer | |
| 561 | ); | |
| 562 | ||
| 563 | /** | |
| 440 | 564 | * Appends data to a CxBuffer. |
| 565 | * | |
| 566 | * The data is always appended to current data within the buffer, | |
| 567 | * regardless of the current position. | |
| 568 | * This is especially useful when the buffer is primarily meant for reading | |
| 569 | * while additional data is added to the buffer occasionally. | |
| 570 | * Consequently, the position of the buffer is unchanged after this operation. | |
| 571 | * | |
| 572 | * @note The signature is compatible with the fwrite() family of functions. | |
| 573 | * | |
| 574 | * @param ptr a pointer to the memory area containing the bytes to be written | |
| 575 | * @param size the length of one element | |
| 576 | * @param nitems the element count | |
| 577 | * @param buffer the CxBuffer to write to | |
| 578 | * @return the total count of elements written | |
| 579 | * @see cxBufferWrite() | |
| 580 | * @see cxBufferRead() | |
| 581 | */ | |
| 582 | cx_attr_nonnull | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
583 | cx_attr_export |
| 440 | 584 | size_t cxBufferAppend( |
| 585 | const void *ptr, | |
| 586 | size_t size, | |
| 587 | size_t nitems, | |
| 588 | CxBuffer *buffer | |
| 589 | ); | |
| 590 | ||
| 591 | /** | |
| 592 | * Performs a single flush-run on the specified buffer. | |
| 593 | * | |
| 594 | * Does nothing when the position in the buffer is zero. | |
| 595 | * Otherwise, the data until the current position minus | |
| 596 | * one is considered for flushing. | |
| 597 | * Note carefully that flushing will never exceed the | |
| 598 | * current @em position, even when the size of the | |
| 599 | * buffer is larger than the current position. | |
| 600 | * | |
| 601 | * One flush run will try to flush @c blkmax many | |
| 602 | * blocks of size @c blksize until either the @p buffer | |
| 603 | * has no more data to flush or the write function | |
| 604 | * used for flushing returns zero. | |
| 605 | * | |
| 606 | * The buffer is shifted left for that many bytes | |
| 607 | * the flush operation has successfully flushed. | |
| 608 | * | |
| 609 | * @par Example 1 | |
| 610 | * Assume you have a buffer with size 340 and you are | |
| 611 | * at position 200. The flush configuration is | |
| 612 | * @c blkmax=4 and @c blksize=64 . | |
| 613 | * Assume that the entire flush operation is successful. | |
| 845 | 614 | * All 200 bytes on the left-hand-side from the current |
| 440 | 615 | * position are written. |
| 845 | 616 | * That means the size of the buffer is now 140 and the |
| 440 | 617 | * position is zero. |
| 618 | * | |
| 619 | * @par Example 2 | |
| 620 | * Same as Example 1, but now the @c blkmax is 1. | |
| 845 | 621 | * The size of the buffer is now 276, and the position is 136. |
| 440 | 622 | * |
| 623 | * @par Example 3 | |
| 624 | * Same as Example 1, but now assume the flush target | |
| 625 | * only accepts 100 bytes before returning zero. | |
| 845 | 626 | * That means the flush operation manages to flush |
| 440 | 627 | * one complete block and one partial block, ending |
| 628 | * up with a buffer with size 240 and position 100. | |
| 629 | * | |
| 630 | * @remark Just returns zero when flushing was not enabled with | |
| 631 | * cxBufferEnableFlushing(). | |
| 632 | * | |
| 633 | * @remark When the buffer uses copy-on-write, the memory | |
| 634 | * is copied first, before attempting any flush. | |
| 635 | * This is, however, considered an erroneous use of the | |
| 845 | 636 | * buffer because it makes little sense to put |
| 637 | * readonly data into an UCX buffer for flushing instead | |
| 440 | 638 | * of writing it directly to the target. |
| 639 | * | |
| 640 | * @param buffer the buffer | |
| 641 | * @return the number of successfully flushed bytes | |
| 642 | * @see cxBufferEnableFlushing() | |
| 643 | */ | |
| 644 | cx_attr_nonnull | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
645 | cx_attr_export |
| 440 | 646 | size_t cxBufferFlush(CxBuffer *buffer); |
| 647 | ||
| 648 | /** | |
| 174 | 649 | * Reads data from a CxBuffer. |
| 650 | * | |
| 651 | * The position of the buffer is increased by the number of bytes read. | |
| 652 | * | |
| 440 | 653 | * @note The signature is compatible with the fread() family of functions. |
| 174 | 654 | * |
| 655 | * @param ptr a pointer to the memory area where to store the read data | |
| 656 | * @param size the length of one element | |
| 657 | * @param nitems the element count | |
| 658 | * @param buffer the CxBuffer to read from | |
| 659 | * @return the total number of elements read | |
| 440 | 660 | * @see cxBufferWrite() |
| 661 | * @see cxBufferAppend() | |
| 174 | 662 | */ |
| 440 | 663 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
664 | cx_attr_export |
| 174 | 665 | size_t cxBufferRead( |
| 666 | void *ptr, | |
| 667 | size_t size, | |
| 668 | size_t nitems, | |
| 669 | CxBuffer *buffer | |
| 670 | ); | |
| 671 | ||
| 672 | /** | |
| 673 | * Writes a character to a buffer. | |
| 674 | * | |
| 675 | * The least significant byte of the argument is written to the buffer. If the | |
| 676 | * end of the buffer is reached and #CX_BUFFER_AUTO_EXTEND feature is enabled, | |
| 440 | 677 | * the buffer capacity is extended by cxBufferMinimumCapacity(). If the feature |
| 845 | 678 | * is disabled or the buffer extension fails, @c EOF is returned. |
| 174 | 679 | * |
| 845 | 680 | * On successful writing, the position of the buffer is increased. |
| 174 | 681 | * |
| 440 | 682 | * If you just want to write a null-terminator at the current position, you |
| 683 | * should use cxBufferTerminate() instead. | |
| 684 | * | |
| 174 | 685 | * @param buffer the buffer to write to |
| 686 | * @param c the character to write | |
| 440 | 687 | * @return the byte that has been written or @c EOF when the end of the stream is |
| 845 | 688 | * reached, and automatic extension is not enabled or not possible |
| 440 | 689 | * @see cxBufferTerminate() |
| 174 | 690 | */ |
| 440 | 691 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
692 | cx_attr_export |
| 174 | 693 | int cxBufferPut( |
| 694 | CxBuffer *buffer, | |
| 695 | int c | |
| 696 | ); | |
| 697 | ||
| 698 | /** | |
| 440 | 699 | * Writes a terminating zero to a buffer at the current position. |
| 700 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
701 | * If successful, sets the size to the current position and advances the position by one. |
| 440 | 702 | * |
| 703 | * The purpose of this function is to have the written data ready to be used as | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
704 | * a C string with the buffer's size being the length of that string. |
| 440 | 705 | * |
| 706 | * @param buffer the buffer to write to | |
| 707 | * @return zero, if the terminator could be written, non-zero otherwise | |
| 708 | */ | |
| 709 | cx_attr_nonnull | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
710 | cx_attr_export |
| 440 | 711 | int cxBufferTerminate(CxBuffer *buffer); |
| 712 | ||
| 713 | /** | |
| 174 | 714 | * Writes a string to a buffer. |
| 715 | * | |
| 440 | 716 | * This is a convenience function for <code>cxBufferWrite(str, 1, strlen(str), buffer)</code>. |
| 717 | * | |
| 174 | 718 | * @param buffer the buffer |
| 719 | * @param str the zero-terminated string | |
| 720 | * @return the number of bytes written | |
| 721 | */ | |
| 440 | 722 | cx_attr_nonnull |
| 723 | 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
|
724 | cx_attr_export |
| 174 | 725 | size_t cxBufferPutString( |
| 726 | CxBuffer *buffer, | |
| 727 | const char *str | |
| 728 | ); | |
| 729 | ||
| 730 | /** | |
| 731 | * Gets a character from a buffer. | |
| 732 | * | |
| 733 | * The current position of the buffer is increased after a successful read. | |
| 734 | * | |
| 735 | * @param buffer the buffer to read from | |
| 440 | 736 | * @return the character or @c EOF, if the end of the buffer is reached |
| 174 | 737 | */ |
| 440 | 738 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
739 | cx_attr_export |
| 174 | 740 | int cxBufferGet(CxBuffer *buffer); |
| 741 | ||
| 742 | #ifdef __cplusplus | |
| 743 | } | |
| 744 | #endif | |
| 745 | ||
| 746 | #endif // UCX_BUFFER_H |