Automatically growing buffer.
More...
|
VTM_API struct vtm_buf * | vtm_buf_new (enum vtm_byteorder order) |
|
VTM_API void | vtm_buf_init (struct vtm_buf *buf, enum vtm_byteorder order) |
|
VTM_API void | vtm_buf_release (struct vtm_buf *buf) |
|
VTM_API void | vtm_buf_free (struct vtm_buf *buf) |
|
VTM_API void | vtm_buf_clear (struct vtm_buf *buf) |
|
VTM_API int | vtm_buf_ensure (struct vtm_buf *buf, size_t space) |
|
VTM_API void | vtm_buf_discard_processed (struct vtm_buf *buf) |
|
VTM_API int | vtm_buf_mark_processed (struct vtm_buf *buf, size_t num) |
|
VTM_API int | vtm_buf_geto (struct vtm_buf *buf, void *dst, size_t len, enum vtm_byteorder dst_order) |
|
VTM_API int | vtm_buf_getm (struct vtm_buf *buf, void *dst, size_t len) |
|
VTM_API int | vtm_buf_puto (struct vtm_buf *buf, const void *src, size_t len, enum vtm_byteorder src_order) |
|
VTM_API int | vtm_buf_putm (struct vtm_buf *buf, const void *src, size_t len) |
|
VTM_API int | vtm_buf_puts (struct vtm_buf *buf, const char *str) |
|
VTM_API int | vtm_buf_putc (struct vtm_buf *buf, unsigned char c) |
|
#define VTM_BUF_GET_AVAIL |
( |
|
BUF_PTR, |
|
|
|
NUM |
|
) |
| |
Value:((BUF_PTR)->read + NUM <= (BUF_PTR)->used && \
(BUF_PTR)->read + NUM >= (BUF_PTR)->read)
Checks if buffer has NUM unprocessed bytes available
#define VTM_BUF_GET_AVAIL_TOTAL |
( |
|
BUF_PTR | ) |
((BUF_PTR)->used - (BUF_PTR)->read) |
Gets the total number of unprocessed bytes
#define VTM_BUF_GETC |
( |
|
BUF_PTR | ) |
((BUF_PTR)->data[(BUF_PTR)->read++]) |
Reads one character from the buffer
#define VTM_BUF_PUT_AVAIL |
( |
|
BUF_PTR, |
|
|
|
NUM |
|
) |
| |
Value:((BUF_PTR)->used + NUM <= (BUF_PTR)->len && \
(BUF_PTR)->used + NUM >= (BUF_PTR)->used)
Checks if buffer has space for additional NUM bytes
#define VTM_BUF_PUT_AVAIL_TOTAL |
( |
|
BUF_PTR | ) |
((BUF_PTR)->len - (BUF_PTR)->used) |
Space left in the buffer in bytes
#define VTM_BUF_PUT_PTR |
( |
|
BUF_PTR | ) |
((BUF_PTR)->data + (BUF_PTR)->used) |
Get pointer to begin of unused memory
#define VTM_BUF_PUT_INC |
( |
|
BUF_PTR, |
|
|
|
NUM |
|
) |
| ((BUF_PTR)->used += NUM) |
Increases the number of used bytes
#define VTM_BUF_PROCESS_ALL |
( |
|
BUF_PTR | ) |
(BUF_PTR)->read = (BUF_PTR)->used |
Marks all bytes in the buffer as processed
Creates a new buffer on the heap.
- Parameters
-
order | the byteorder of the buffer |
- Returns
- pointer to created buffer
-
NULL if an error occured
Initializes given buffer.
- Parameters
-
buf | the buffer that should be initialized |
order | the byteorder of the buffer |
VTM_API void vtm_buf_release |
( |
struct vtm_buf * |
buf | ) |
|
Releases the buffer and all allocated resources
- Parameters
-
buf | the buffer that should be released |
VTM_API void vtm_buf_free |
( |
struct vtm_buf * |
buf | ) |
|
Releases the buffer and frees the pointer to it.
After this call the buffer pointer is no longer valid.
- Parameters
-
buf | the buffer that should be freed |
VTM_API void vtm_buf_clear |
( |
struct vtm_buf * |
buf | ) |
|
Resets the buffer so that there are no more used or processed bytes.
- Parameters
-
buf | the buffer that should be cleared |
VTM_API int vtm_buf_ensure |
( |
struct vtm_buf * |
buf, |
|
|
size_t |
space |
|
) |
| |
Ensures that the buffer has enough free space to store the given number of bytes.
- Parameters
-
buf | the buffer |
space | the number of bytes |
- Returns
- VTM_OK if the buffer has enough free space
-
VTM_E_MALLOC or VTM_ERROR if an error occured
VTM_API void vtm_buf_discard_processed |
( |
struct vtm_buf * |
buf | ) |
|
Removes already processed bytes from the buffer.
- Parameters
-
buf | the buffer that should discard processed bytes |
VTM_API int vtm_buf_mark_processed |
( |
struct vtm_buf * |
buf, |
|
|
size_t |
num |
|
) |
| |
Marks the given number of bytes as processed.
- Parameters
-
buf | the buffer where the bytes should be marked |
num | the number of bytes that should be marked |
- Returns
- VTM_OK if the bytes were successfully marked
-
VTM_E_OVERFLOW if the number of processed bytes would overflow
VTM_API int vtm_buf_geto |
( |
struct vtm_buf * |
buf, |
|
|
void * |
dst, |
|
|
size_t |
len, |
|
|
enum vtm_byteorder |
dst_order |
|
) |
| |
Copies given amount of bytes from the buffer to destination.
If necessary the data is transformed to match the destination byte order.
- Parameters
-
buf | the buffer where the data should be read from |
dst | the target buffer where the data is copied to |
len | the number of bytes that should be copied |
dst_order | the output byteorder |
- Returns
- VTM_OK if the bytes were read successfully
-
VTM_ERROR if any error has already occured in a previous call and the buffer was not reset
VTM_API int vtm_buf_getm |
( |
struct vtm_buf * |
buf, |
|
|
void * |
dst, |
|
|
size_t |
len |
|
) |
| |
Copies given amount of bytes from the buffer to destination.
- Parameters
-
buf | the buffer where the data should be read from |
dst | the target buffer where the data is copied to |
len | the number of bytes that should be copied |
- Returns
- VTM_OK if the bytes were read successfully
-
VTM_ERROR if any error has already occured in a previous call and the buffer was not reset
VTM_API int vtm_buf_puto |
( |
struct vtm_buf * |
buf, |
|
|
const void * |
src, |
|
|
size_t |
len, |
|
|
enum vtm_byteorder |
src_order |
|
) |
| |
Stores given amount of bytes in the buffer.
If necessary the data is transformed to match the byte order of the buffer.
- Parameters
-
buf | the buffer where the data should be stored |
src | the source where the data is copied from |
len | the number of bytes that should be copied |
src_order | the input byteorder |
- Returns
- VTM_OK if the bytes were stored successfully
-
VTM_ERROR if any error has already occured in a previous call and the buffer was not reset
VTM_API int vtm_buf_putm |
( |
struct vtm_buf * |
buf, |
|
|
const void * |
src, |
|
|
size_t |
len |
|
) |
| |
Stores given amount of bytes in the buffer.
- Parameters
-
buf | the buffer where the data should be stored |
src | the source where the data is copied from |
len | the number of bytes that should be copied |
- Returns
- VTM_OK if the bytes were stored successfully
-
VTM_ERROR if any error has already occured in a previous call and the buffer was not reset
VTM_API int vtm_buf_puts |
( |
struct vtm_buf * |
buf, |
|
|
const char * |
str |
|
) |
| |
Stores given string in the buffer.
- Parameters
-
buf | the buffer where the string should be stored |
str | the source string that is copied to the buffer |
- Returns
- VTM_OK if the string was stored successfully
-
VTM_ERROR if any error has already occured in a previous call and the buffer was not reset
VTM_API int vtm_buf_putc |
( |
struct vtm_buf * |
buf, |
|
|
unsigned char |
c |
|
) |
| |
Stores given character in the buffer.
- Parameters
-
buf | the buffer where the character should be stored |
c | the character that should be stored |
- Returns
- VTM_OK if the bytes were stored successfully
-
VTM_ERROR if any error has already occured in a previous call and the buffer was not reset