Sun, 23 Mar 2025 12:26:03 +0100
more documentation for buffer.h + set errno in cxBufferSeek() on invalid whence argument
relates to #451
docs/Writerside/topics/buffer.h.md | file | annotate | diff | comparison | revisions | |
src/buffer.c | file | annotate | diff | comparison | revisions |
--- a/docs/Writerside/topics/buffer.h.md Sun Mar 23 11:28:20 2025 +0100 +++ b/docs/Writerside/topics/buffer.h.md Sun Mar 23 12:26:03 2025 +0100 @@ -54,9 +54,11 @@ void cxBufferFree(CxBuffer *buffer); ``` -<warning> -TODO: document -</warning> +The above functions destroy the buffer and deallocate the buffer's memory when the `CX_BUFFER_FREE_CONTENTS` flag is set. + +The function `cxBufferDestroy()` is to be used when the buffer was initialized with `cxBufferInit()`, +and the function `cxBufferFree()` is to be used when the buffer was created with `cxBufferCreate()`. +The only difference is, that `cxBufferFree()` additionally deallocates the memory of the `CxBuffer` structure. ## Write @@ -91,6 +93,8 @@ CxBuffer *buffer); int cxBufferGet(CxBuffer *buffer); + +bool cxBufferEof(const CxBuffer *buffer); ``` <warning> @@ -117,13 +121,16 @@ #include <cx/buffer.h> int cxBufferSeek(CxBuffer *buffer, off_t offset, int whence); - -bool cxBufferEof(const CxBuffer *buffer); ``` -<warning> -TODO: document -</warning> +The function `cxBufferSeek()` is a `fseek()`-like function that sets the current position in the buffer +relative to the start (when `whence` is `SEEK_SET`), the current position (when `whence` is `SEEK_CUR`), +or end (when `whence` is `SEEK_END`) of the buffer. + +If the resulting position is negative, or larger than the size (i.e. the first unused byte), +this function returns non-zero and sets `errno` to `EOVERFLOW`. + +> Note that the error behavior of `cxBufferSeek()` is not exactly the same as for POSIX `fseek()`. ## Shift Contents