| 200 * |
200 * |
| 201 * You may also provide a read-only @p space, in which case |
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 |
202 * you will need to cast the pointer, and you should set the |
| 203 * #CX_BUFFER_COPY_ON_WRITE flag. |
203 * #CX_BUFFER_COPY_ON_WRITE flag. |
| 204 * |
204 * |
| 205 * You need to set the size manually after initialization, if |
205 * You need to set the size manually after initialization if |
| 206 * you provide @p space which already contains data. |
206 * you provide @p space which already contains data. |
| 207 * |
207 * |
| 208 * When you specify stack memory as @p space and decide to use |
208 * When you specify stack memory as @p space and decide to use |
| 209 * the auto-extension feature, you @em must use the |
209 * the auto-extension feature, you @em must use the |
| 210 * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the |
210 * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the |
| 211 * #CX_BUFFER_AUTO_EXTEND flag. |
211 * #CX_BUFFER_AUTO_EXTEND flag. |
| 212 * |
212 * |
| 213 * @note You may provide @c NULL as argument for @p space. |
213 * @note You may provide @c NULL as the argument for @p space. |
| 214 * Then this function will allocate the space and enforce |
214 * Then this function will allocate the space and enforce |
| 215 * the #CX_BUFFER_FREE_CONTENTS flag. In that case, specifying |
215 * the #CX_BUFFER_FREE_CONTENTS flag. In that case, specifying |
| 216 * copy-on-write should be avoided, because the allocated |
216 * copy-on-write should be avoided, because the allocated |
| 217 * space will be leaking after the copy-on-write operation. |
217 * space will be leaking after the copy-on-write operation. |
| 218 * |
218 * |
| 220 * @param space pointer to the memory area, or @c NULL to allocate |
220 * @param space pointer to the memory area, or @c NULL to allocate |
| 221 * new memory |
221 * new memory |
| 222 * @param capacity the capacity of the buffer |
222 * @param capacity the capacity of the buffer |
| 223 * @param allocator the allocator this buffer shall use for automatic |
223 * @param allocator the allocator this buffer shall use for automatic |
| 224 * memory management |
224 * memory management |
| 225 * (if @c NULL, a default stdlib allocator will be used) |
225 * (if @c NULL, the cxDefaultAllocator will be used) |
| 226 * @param flags buffer features (see cx_buffer_s.flags) |
226 * @param flags buffer features (see cx_buffer_s.flags) |
| 227 * @return zero on success, non-zero if a required allocation failed |
227 * @return zero on success, non-zero if a required allocation failed |
| 228 */ |
228 */ |
| 229 cx_attr_nonnull_arg(1) |
229 cx_attr_nonnull_arg(1) |
| 230 cx_attr_export |
230 CX_EXPORT int cxBufferInit(CxBuffer *buffer, void *space, size_t capacity, |
| 231 int cxBufferInit( |
231 const CxAllocator *allocator, int flags); |
| 232 CxBuffer *buffer, |
|
| 233 void *space, |
|
| 234 size_t capacity, |
|
| 235 const CxAllocator *allocator, |
|
| 236 int flags |
|
| 237 ); |
|
| 238 |
232 |
| 239 /** |
233 /** |
| 240 * Configures the buffer for flushing. |
234 * Configures the buffer for flushing. |
| 241 * |
235 * |
| 242 * Flushing can happen automatically when data is written |
236 * Flushing can happen automatically when data is written |
| 265 * |
255 * |
| 266 * @param buffer the buffer which contents shall be destroyed |
256 * @param buffer the buffer which contents shall be destroyed |
| 267 * @see cxBufferInit() |
257 * @see cxBufferInit() |
| 268 */ |
258 */ |
| 269 cx_attr_nonnull |
259 cx_attr_nonnull |
| 270 cx_attr_export |
260 CX_EXPORT void cxBufferDestroy(CxBuffer *buffer); |
| 271 void cxBufferDestroy(CxBuffer *buffer); |
|
| 272 |
261 |
| 273 /** |
262 /** |
| 274 * Deallocates the buffer. |
263 * Deallocates the buffer. |
| 275 * |
264 * |
| 276 * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, this function also destroys |
265 * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, this function also destroys |
| 277 * the contents. If you @em only want to destroy the contents, use cxBufferDestroy(). |
266 * the contents. If you @em only want to destroy the contents, use cxBufferDestroy(). |
| 278 * |
267 * |
| 279 * @remark As with all free() functions, this accepts @c NULL arguments in which |
|
| 280 * case it does nothing. |
|
| 281 * |
|
| 282 * @param buffer the buffer to deallocate |
268 * @param buffer the buffer to deallocate |
| 283 * @see cxBufferCreate() |
269 * @see cxBufferCreate() |
| 284 */ |
270 */ |
| 285 cx_attr_export |
271 CX_EXPORT void cxBufferFree(CxBuffer *buffer); |
| 286 void cxBufferFree(CxBuffer *buffer); |
|
| 287 |
272 |
| 288 /** |
273 /** |
| 289 * Allocates and initializes a fresh buffer. |
274 * Allocates and initializes a fresh buffer. |
| 290 * |
275 * |
| 291 * You may also provide a read-only @p space, in which case |
276 * You may also provide a read-only @p space, in which case |
| 294 * When you specify stack memory as @p space and decide to use |
279 * When you specify stack memory as @p space and decide to use |
| 295 * the auto-extension feature, you @em must use the |
280 * the auto-extension feature, you @em must use the |
| 296 * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the |
281 * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the |
| 297 * #CX_BUFFER_AUTO_EXTEND flag. |
282 * #CX_BUFFER_AUTO_EXTEND flag. |
| 298 * |
283 * |
| 299 * @note You may provide @c NULL as argument for @p space. |
284 * @note You may provide @c NULL as the argument for @p space. |
| 300 * Then this function will allocate the space and enforce |
285 * Then this function will allocate the space and enforce |
| 301 * the #CX_BUFFER_FREE_CONTENTS flag. |
286 * the #CX_BUFFER_FREE_CONTENTS flag. |
| 302 * |
287 * |
| 303 * @param space pointer to the memory area, or @c NULL to allocate |
288 * @param space pointer to the memory area, or @c NULL to allocate |
| 304 * new memory |
289 * new memory |
| 305 * @param capacity the capacity of the buffer |
290 * @param capacity the capacity of the buffer |
| 306 * @param allocator the allocator to use for allocating the structure and the automatic |
291 * @param allocator the allocator to use for allocating the structure and the automatic |
| 307 * memory management within the buffer |
292 * memory management within the buffer |
| 308 * (if @c NULL, a default stdlib allocator will be used) |
293 * (if @c NULL, the cxDefaultAllocator will be used) |
| 309 * @param flags buffer features (see cx_buffer_s.flags) |
294 * @param flags buffer features (see cx_buffer_s.flags) |
| 310 * @return a pointer to the buffer on success, @c NULL if a required allocation failed |
295 * @return a pointer to the buffer on success, @c NULL if a required allocation failed |
| 311 */ |
296 */ |
| 312 cx_attr_malloc |
297 cx_attr_malloc cx_attr_dealloc(cxBufferFree, 1) cx_attr_nodiscard |
| 313 cx_attr_dealloc(cxBufferFree, 1) |
298 CX_EXPORT CxBuffer *cxBufferCreate(void *space, size_t capacity, |
| 314 cx_attr_nodiscard |
299 const CxAllocator *allocator, int flags); |
| 315 cx_attr_export |
|
| 316 CxBuffer *cxBufferCreate( |
|
| 317 void *space, |
|
| 318 size_t capacity, |
|
| 319 const CxAllocator *allocator, |
|
| 320 int flags |
|
| 321 ); |
|
| 322 |
300 |
| 323 /** |
301 /** |
| 324 * Shifts the contents of the buffer by the given offset. |
302 * Shifts the contents of the buffer by the given offset. |
| 325 * |
303 * |
| 326 * If the offset is positive, the contents are shifted to the right. |
304 * If the offset is positive, the contents are shifted to the right. |
| 327 * If auto extension is enabled, the buffer grows, if necessary. |
305 * If auto extension is enabled, the buffer grows, if necessary. |
| 328 * In case the auto extension fails, this function returns a non-zero value and |
306 * In case the auto extension fails, this function returns a non-zero value and |
| 329 * no contents are changed. |
307 * no contents are changed. |
| 330 * If auto extension is disabled, the contents that do not fit into the buffer |
308 * When the auto extension is disabled, the contents that do not fit into the |
| 331 * are discarded. |
309 * buffer are discarded. |
| 332 * |
310 * |
| 333 * If the offset is negative, the contents are shifted to the left where the |
311 * If the offset is negative, the contents are shifted to the left where the |
| 334 * first @p shift bytes are discarded. |
312 * first @p shift bytes are discarded. |
| 335 * The new size of the buffer is the old size minus the absolute shift value. |
313 * The new size of the buffer is the old size minus the absolute shift value. |
| 336 * If this value is larger than the buffer size, the buffer is emptied (but |
314 * If this value is larger than the buffer size, the buffer is emptied (but |
| 337 * not cleared, see the security note below). |
315 * not cleared, see the security note below). |
| 338 * |
316 * |
| 339 * The buffer position gets shifted alongside with the content but is kept |
317 * The buffer position gets shifted alongside the content but is kept |
| 340 * within the boundaries of the buffer. |
318 * within the boundaries of the buffer. |
| 341 * |
319 * |
| 342 * @note For situations where @c off_t is not large enough, there are specialized cxBufferShiftLeft() and |
320 * @note For situations where @c off_t is not large enough, there are specialized cxBufferShiftLeft() and |
| 343 * cxBufferShiftRight() functions using a @c size_t as parameter type. |
321 * cxBufferShiftRight() functions using a @c size_t as the parameter type. |
| 344 * |
322 * |
| 345 * @attention |
323 * @attention |
| 346 * Security Note: The shifting operation does @em not erase the previously occupied memory cells. |
324 * Security Note: The shifting operation does @em not erase the previously occupied memory cells. |
| 347 * But you can easily do that manually, e.g. by calling |
325 * But you can do that manually by calling |
| 348 * <code>memset(buffer->bytes, 0, shift)</code> for a right shift or |
326 * <code>memset(buffer->bytes, 0, shift)</code> for a right shift or |
| 349 * <code>memset(buffer->bytes + buffer->size, 0, buffer->capacity - buffer->size)</code> |
327 * <code>memset(buffer->bytes + buffer->size, 0, buffer->capacity - buffer->size)</code> |
| 350 * for a left shift. |
328 * for a left shift. |
| 351 * |
329 * |
| 352 * @param buffer the buffer |
330 * @param buffer the buffer |
| 450 * |
410 * |
| 451 * @param buffer the buffer to be cleared |
411 * @param buffer the buffer to be cleared |
| 452 * @see cxBufferClear() |
412 * @see cxBufferClear() |
| 453 */ |
413 */ |
| 454 cx_attr_nonnull |
414 cx_attr_nonnull |
| 455 cx_attr_export |
415 CX_EXPORT void cxBufferReset(CxBuffer *buffer); |
| 456 void cxBufferReset(CxBuffer *buffer); |
|
| 457 |
416 |
| 458 /** |
417 /** |
| 459 * Tests, if the buffer position has exceeded the buffer size. |
418 * Tests, if the buffer position has exceeded the buffer size. |
| 460 * |
419 * |
| 461 * @param buffer the buffer to test |
420 * @param buffer the buffer to test |
| 462 * @retval true if the current buffer position has exceeded the last |
421 * @retval true if the current buffer position has exceeded the last |
| 463 * byte of the buffer's contents |
422 * byte of the buffer's contents |
| 464 * @retval false otherwise |
423 * @retval false otherwise |
| 465 */ |
424 */ |
| 466 cx_attr_nonnull |
425 cx_attr_nonnull cx_attr_nodiscard |
| 467 cx_attr_nodiscard |
426 CX_EXPORT bool cxBufferEof(const CxBuffer *buffer); |
| 468 cx_attr_export |
|
| 469 bool cxBufferEof(const CxBuffer *buffer); |
|
| 470 |
427 |
| 471 |
428 |
| 472 /** |
429 /** |
| 473 * Ensures that the buffer has a minimum capacity. |
430 * Ensures that the buffer has a minimum capacity. |
| 474 * |
431 * |
| 475 * If the current capacity is not sufficient, the buffer will be extended. |
432 * If the current capacity is not sufficient, the buffer will be extended. |
| |
433 * |
| |
434 * The new capacity will be a power of two until the system's page size is reached. |
| |
435 * Then, the new capacity will be a multiple of the page size. |
| 476 * |
436 * |
| 477 * @param buffer the buffer |
437 * @param buffer the buffer |
| 478 * @param capacity the minimum required capacity for this buffer |
438 * @param capacity the minimum required capacity for this buffer |
| 479 * @retval zero the capacity was already sufficient or successfully increased |
439 * @retval zero the capacity was already sufficient or successfully increased |
| 480 * @retval non-zero on allocation failure |
440 * @retval non-zero on allocation failure |
| 481 */ |
441 * @see cxBufferShrink() |
| 482 cx_attr_nonnull |
442 */ |
| 483 cx_attr_export |
443 cx_attr_nonnull |
| 484 int cxBufferMinimumCapacity( |
444 CX_EXPORT int cxBufferMinimumCapacity(CxBuffer *buffer, size_t capacity); |
| 485 CxBuffer *buffer, |
445 |
| 486 size_t capacity |
446 /** |
| 487 ); |
447 * Shrinks the capacity of the buffer to fit its current size. |
| |
448 * |
| |
449 * If @p reserve is larger than zero, the buffer is shrunk to its size plus |
| |
450 * the number of reserved bytes. |
| |
451 * |
| |
452 * If the current capacity is not larger than the size plus the reserved bytes, |
| |
453 * nothing happens. |
| |
454 * |
| |
455 * If the #CX_BUFFER_COPY_ON_WRITE or #CX_BUFFER_COPY_ON_EXTEND flag is set, |
| |
456 * this function does nothing. |
| |
457 * |
| |
458 * @param buffer the buffer |
| |
459 * @param reserve the number of bytes that shall remain reserved |
| |
460 * @see cxBufferMinimumCapacity() |
| |
461 */ |
| |
462 cx_attr_nonnull |
| |
463 CX_EXPORT void cxBufferShrink(CxBuffer *buffer, size_t reserve); |
| 488 |
464 |
| 489 /** |
465 /** |
| 490 * Writes data to a CxBuffer. |
466 * Writes data to a CxBuffer. |
| 491 * |
467 * |
| 492 * If automatic flushing is not enabled, the data is simply written into the |
468 * If automatic flushing is not enabled, the data is simply written into the |
| 493 * buffer at the current position and the position of the buffer is increased |
469 * buffer at the current position, and the position of the buffer is increased |
| 494 * by the number of bytes written. |
470 * by the number of bytes written. |
| 495 * |
471 * |
| 496 * If flushing is enabled and the buffer needs to flush, the data is flushed to |
472 * If flushing is enabled and the buffer needs to flush, the data is flushed to |
| 497 * the target until the target signals that it cannot take more data by |
473 * the target until the target signals that it cannot take more data by |
| 498 * returning zero via the respective write function. In that case, the remaining |
474 * returning zero via the respective write function. In that case, the remaining |
| 499 * data in this buffer is shifted to the beginning of this buffer so that the |
475 * data in this buffer is shifted to the beginning of this buffer so that the |
| 500 * newly available space can be used to append as much data as possible. |
476 * newly available space can be used to append as much data as possible. |
| 501 * |
477 * |
| 502 * This function only stops writing more elements, when the flush target and this |
478 * This function only stops writing more elements when the flush target and this |
| 503 * buffer are both incapable of taking more data or all data has been written. |
479 * buffer are both incapable of taking more data or all data has been written. |
| 504 * |
480 * |
| 505 * If, after flushing, the number of items that shall be written still exceeds |
481 * If, after flushing, the number of items that shall be written still exceeds |
| 506 * the capacity or flush threshold, this function tries to write all items directly |
482 * the capacity or flush threshold, this function tries to write all items directly |
| 507 * to the flush target, if possible. |
483 * to the flush target, if possible. |
| 508 * |
484 * |
| 509 * The number returned by this function is the number of elements from |
485 * The number returned by this function is the number of elements from |
| 510 * @c ptr that could be written to either the flush target or the buffer |
486 * @c ptr that could be written to either the flush target or the buffer. |
| 511 * (so it does not include the number of items that had been already in the buffer |
487 * That means it does @em not include the number of items that were already in |
| 512 * in were flushed during the process). |
488 * the buffer and were also flushed during the process. |
| 513 * |
489 * |
| 514 * @attention |
490 * @attention |
| 515 * When @p size is larger than one and the contents of the buffer are not aligned |
491 * When @p size is larger than one and the contents of the buffer are not aligned |
| 516 * with @p size, flushing stops after all complete items have been flushed, leaving |
492 * with @p size, flushing stops after all complete items have been flushed, leaving |
| 517 * the mis-aligned part in the buffer. |
493 * the misaligned part in the buffer. |
| 518 * Afterward, this function only writes as many items as possible to the buffer. |
494 * Afterward, this function only writes as many items as possible to the buffer. |
| 519 * |
495 * |
| 520 * @note The signature is compatible with the fwrite() family of functions. |
496 * @note The signature is compatible with the fwrite() family of functions. |
| 521 * |
497 * |
| 522 * @param ptr a pointer to the memory area containing the bytes to be written |
498 * @param ptr a pointer to the memory area containing the bytes to be written |
| 585 * @par Example 1 |
551 * @par Example 1 |
| 586 * Assume you have a buffer with size 340 and you are |
552 * Assume you have a buffer with size 340 and you are |
| 587 * at position 200. The flush configuration is |
553 * at position 200. The flush configuration is |
| 588 * @c blkmax=4 and @c blksize=64 . |
554 * @c blkmax=4 and @c blksize=64 . |
| 589 * Assume that the entire flush operation is successful. |
555 * Assume that the entire flush operation is successful. |
| 590 * All 200 bytes on the left hand-side from the current |
556 * All 200 bytes on the left-hand-side from the current |
| 591 * position are written. |
557 * position are written. |
| 592 * That means, the size of the buffer is now 140 and the |
558 * That means the size of the buffer is now 140 and the |
| 593 * position is zero. |
559 * position is zero. |
| 594 * |
560 * |
| 595 * @par Example 2 |
561 * @par Example 2 |
| 596 * Same as Example 1, but now the @c blkmax is 1. |
562 * Same as Example 1, but now the @c blkmax is 1. |
| 597 * The size of the buffer is now 276 and the position is 136. |
563 * The size of the buffer is now 276, and the position is 136. |
| 598 * |
564 * |
| 599 * @par Example 3 |
565 * @par Example 3 |
| 600 * Same as Example 1, but now assume the flush target |
566 * Same as Example 1, but now assume the flush target |
| 601 * only accepts 100 bytes before returning zero. |
567 * only accepts 100 bytes before returning zero. |
| 602 * That means, the flush operations manages to flush |
568 * That means the flush operation manages to flush |
| 603 * one complete block and one partial block, ending |
569 * one complete block and one partial block, ending |
| 604 * up with a buffer with size 240 and position 100. |
570 * up with a buffer with size 240 and position 100. |
| 605 * |
571 * |
| 606 * @remark Just returns zero when flushing was not enabled with |
572 * @remark Just returns zero when flushing was not enabled with |
| 607 * cxBufferEnableFlushing(). |
573 * cxBufferEnableFlushing(). |
| 608 * |
574 * |
| 609 * @remark When the buffer uses copy-on-write, the memory |
575 * @remark When the buffer uses copy-on-write, the memory |
| 610 * is copied first, before attempting any flush. |
576 * is copied first, before attempting any flush. |
| 611 * This is, however, considered an erroneous use of the |
577 * This is, however, considered an erroneous use of the |
| 612 * buffer, because it does not make much sense to put |
578 * buffer because it makes little sense to put |
| 613 * readonly data into an UCX buffer for flushing, instead |
579 * readonly data into an UCX buffer for flushing instead |
| 614 * of writing it directly to the target. |
580 * of writing it directly to the target. |
| 615 * |
581 * |
| 616 * @param buffer the buffer |
582 * @param buffer the buffer |
| 617 * @return the number of successfully flushed bytes |
583 * @return the number of successfully flushed bytes |
| 618 * @see cxBufferEnableFlushing() |
584 * @see cxBufferEnableFlushing() |
| 619 */ |
585 */ |
| 620 cx_attr_nonnull |
586 cx_attr_nonnull |
| 621 cx_attr_export |
587 CX_EXPORT size_t cxBufferFlush(CxBuffer *buffer); |
| 622 size_t cxBufferFlush(CxBuffer *buffer); |
|
| 623 |
588 |
| 624 /** |
589 /** |
| 625 * Reads data from a CxBuffer. |
590 * Reads data from a CxBuffer. |
| 626 * |
591 * |
| 627 * The position of the buffer is increased by the number of bytes read. |
592 * The position of the buffer is increased by the number of bytes read. |
| 635 * @return the total number of elements read |
600 * @return the total number of elements read |
| 636 * @see cxBufferWrite() |
601 * @see cxBufferWrite() |
| 637 * @see cxBufferAppend() |
602 * @see cxBufferAppend() |
| 638 */ |
603 */ |
| 639 cx_attr_nonnull |
604 cx_attr_nonnull |
| 640 cx_attr_export |
605 CX_EXPORT size_t cxBufferRead(void *ptr, size_t size, |
| 641 size_t cxBufferRead( |
606 size_t nitems, CxBuffer *buffer); |
| 642 void *ptr, |
|
| 643 size_t size, |
|
| 644 size_t nitems, |
|
| 645 CxBuffer *buffer |
|
| 646 ); |
|
| 647 |
607 |
| 648 /** |
608 /** |
| 649 * Writes a character to a buffer. |
609 * Writes a character to a buffer. |
| 650 * |
610 * |
| 651 * The least significant byte of the argument is written to the buffer. If the |
611 * The least significant byte of the argument is written to the buffer. If the |
| 652 * end of the buffer is reached and #CX_BUFFER_AUTO_EXTEND feature is enabled, |
612 * end of the buffer is reached and #CX_BUFFER_AUTO_EXTEND feature is enabled, |
| 653 * the buffer capacity is extended by cxBufferMinimumCapacity(). If the feature |
613 * the buffer capacity is extended by cxBufferMinimumCapacity(). If the feature |
| 654 * is disabled or buffer extension fails, @c EOF is returned. |
614 * is disabled or the buffer extension fails, @c EOF is returned. |
| 655 * |
615 * |
| 656 * On successful write, the position of the buffer is increased. |
616 * On successful writing, the position of the buffer is increased. |
| 657 * |
617 * |
| 658 * If you just want to write a null-terminator at the current position, you |
618 * If you just want to write a null-terminator at the current position, you |
| 659 * should use cxBufferTerminate() instead. |
619 * should use cxBufferTerminate() instead. |
| 660 * |
620 * |
| 661 * @param buffer the buffer to write to |
621 * @param buffer the buffer to write to |
| 662 * @param c the character to write |
622 * @param c the character to write |
| 663 * @return the byte that has been written or @c EOF when the end of the stream is |
623 * @return the byte that has been written or @c EOF when the end of the stream is |
| 664 * reached and automatic extension is not enabled or not possible |
624 * reached, and automatic extension is not enabled or not possible |
| 665 * @see cxBufferTerminate() |
625 * @see cxBufferTerminate() |
| 666 */ |
626 */ |
| 667 cx_attr_nonnull |
627 cx_attr_nonnull |
| 668 cx_attr_export |
628 CX_EXPORT int cxBufferPut(CxBuffer *buffer, int c); |
| 669 int cxBufferPut( |
|
| 670 CxBuffer *buffer, |
|
| 671 int c |
|
| 672 ); |
|
| 673 |
629 |
| 674 /** |
630 /** |
| 675 * Writes a terminating zero to a buffer at the current position. |
631 * Writes a terminating zero to a buffer at the current position. |
| 676 * |
632 * |
| 677 * On successful write, @em neither the position @em nor the size of the buffer is |
633 * If successful, sets the size to the current position and advances the position by one. |
| 678 * increased. |
|
| 679 * |
634 * |
| 680 * The purpose of this function is to have the written data ready to be used as |
635 * The purpose of this function is to have the written data ready to be used as |
| 681 * a C string. |
636 * a C string with the buffer's size being the length of that string. |
| 682 * |
637 * |
| 683 * @param buffer the buffer to write to |
638 * @param buffer the buffer to write to |
| 684 * @return zero, if the terminator could be written, non-zero otherwise |
639 * @return zero, if the terminator could be written, non-zero otherwise |
| 685 */ |
640 */ |
| 686 cx_attr_nonnull |
641 cx_attr_nonnull |
| 687 cx_attr_export |
642 CX_EXPORT int cxBufferTerminate(CxBuffer *buffer); |
| 688 int cxBufferTerminate(CxBuffer *buffer); |
|
| 689 |
643 |
| 690 /** |
644 /** |
| 691 * Writes a string to a buffer. |
645 * Writes a string to a buffer. |
| 692 * |
646 * |
| 693 * This is a convenience function for <code>cxBufferWrite(str, 1, strlen(str), buffer)</code>. |
647 * This is a convenience function for <code>cxBufferWrite(str, 1, strlen(str), buffer)</code>. |
| 694 * |
648 * |
| 695 * @param buffer the buffer |
649 * @param buffer the buffer |
| 696 * @param str the zero-terminated string |
650 * @param str the zero-terminated string |
| 697 * @return the number of bytes written |
651 * @return the number of bytes written |
| 698 */ |
652 */ |
| 699 cx_attr_nonnull |
653 cx_attr_nonnull cx_attr_cstr_arg(2) |
| 700 cx_attr_cstr_arg(2) |
654 CX_EXPORT size_t cxBufferPutString(CxBuffer *buffer, const char *str); |
| 701 cx_attr_export |
|
| 702 size_t cxBufferPutString( |
|
| 703 CxBuffer *buffer, |
|
| 704 const char *str |
|
| 705 ); |
|
| 706 |
655 |
| 707 /** |
656 /** |
| 708 * Gets a character from a buffer. |
657 * Gets a character from a buffer. |
| 709 * |
658 * |
| 710 * The current position of the buffer is increased after a successful read. |
659 * The current position of the buffer is increased after a successful read. |
| 711 * |
660 * |
| 712 * @param buffer the buffer to read from |
661 * @param buffer the buffer to read from |
| 713 * @return the character or @c EOF, if the end of the buffer is reached |
662 * @return the character or @c EOF, if the end of the buffer is reached |
| 714 */ |
663 */ |
| 715 cx_attr_nonnull |
664 cx_attr_nonnull |
| 716 cx_attr_export |
665 CX_EXPORT int cxBufferGet(CxBuffer *buffer); |
| 717 int cxBufferGet(CxBuffer *buffer); |
|
| 718 |
666 |
| 719 #ifdef __cplusplus |
667 #ifdef __cplusplus |
| 720 } |
668 } |
| 721 #endif |
669 #endif |
| 722 |
670 |