Go to the source code of this file.
Functions | |
ldns_buffer * | ldns_buffer_new (size_t capacity) |
creates a new buffer with the specified capacity. | |
void | ldns_buffer_new_frm_data (ldns_buffer *buffer, void *data, size_t size) |
creates a buffer with the specified data. | |
bool | ldns_buffer_set_capacity (ldns_buffer *buffer, size_t capacity) |
changes the buffer's capacity. | |
bool | ldns_buffer_reserve (ldns_buffer *buffer, size_t amount) |
ensures BUFFER can contain at least AMOUNT more bytes. | |
int | ldns_buffer_printf (ldns_buffer *buffer, const char *format,...) |
prints to the buffer, increasing the capacity if required using buffer_reserve(). | |
void | ldns_buffer_free (ldns_buffer *buffer) |
frees the buffer. | |
void * | ldns_buffer_export (ldns_buffer *buffer) |
Makes the buffer fixed and returns a pointer to the data. | |
int | ldns_bgetc (ldns_buffer *buffer) |
returns the next character from a buffer. | |
void | ldns_buffer_copy (ldns_buffer *result, ldns_buffer *from) |
Copy contents of the other buffer to this buffer. |
ldns_buffer* ldns_buffer_new | ( | size_t | capacity | ) |
creates a new buffer with the specified capacity.
[in] | capacity | the size (in bytes) to allocate for the buffer |
Definition at line 16 of file buffer.c.
References LDNS_MALLOC, ldns_struct_buffer::_data, LDNS_XMALLOC, LDNS_FREE, ldns_struct_buffer::_position, ldns_struct_buffer::_limit, ldns_struct_buffer::_capacity, ldns_struct_buffer::_fixed, ldns_struct_buffer::_status, and LDNS_STATUS_OK.
void ldns_buffer_new_frm_data | ( | ldns_buffer * | buffer, |
void * | data, | ||
size_t | size | ||
) |
creates a buffer with the specified data.
The data IS copied and MEMORY allocations are done. The buffer is not fixed and can be resized using buffer_reserve().
[in] | buffer | pointer to the buffer to put the data in |
[in] | data | the data to encapsulate in the buffer |
[in] | size | the size of the data |
Definition at line 41 of file buffer.c.
References ldns_struct_buffer::_position, ldns_struct_buffer::_limit, ldns_struct_buffer::_capacity, ldns_struct_buffer::_fixed, ldns_struct_buffer::_data, LDNS_XMALLOC, ldns_struct_buffer::_status, LDNS_STATUS_MEM_ERR, and LDNS_STATUS_OK.
bool ldns_buffer_set_capacity | ( | ldns_buffer * | buffer, |
size_t | capacity | ||
) |
changes the buffer's capacity.
The data is reallocated so any pointers to the data may become invalid. The buffer's limit is set to the buffer's new capacity.
[in] | buffer | the buffer |
[in] | capacity | the capacity to use |
Definition at line 60 of file buffer.c.
References ldns_struct_buffer::_position, LDNS_XREALLOC, ldns_struct_buffer::_data, ldns_struct_buffer::_status, LDNS_STATUS_MEM_ERR, ldns_struct_buffer::_limit, and ldns_struct_buffer::_capacity.
bool ldns_buffer_reserve | ( | ldns_buffer * | buffer, |
size_t | amount | ||
) |
ensures BUFFER can contain at least AMOUNT more bytes.
The buffer's capacity is increased if necessary using buffer_set_capacity().
The buffer's limit is always set to the (possibly increased) capacity.
[in] | buffer | the buffer |
[in] | amount | amount to use |
Definition at line 79 of file buffer.c.
References ldns_struct_buffer::_fixed, ldns_struct_buffer::_capacity, ldns_struct_buffer::_position, ldns_buffer_set_capacity(), ldns_struct_buffer::_status, LDNS_STATUS_MEM_ERR, and ldns_struct_buffer::_limit.
int ldns_buffer_printf | ( | ldns_buffer * | buffer, |
const char * | format, | ||
... | |||
) |
prints to the buffer, increasing the capacity if required using buffer_reserve().
The buffer's position is set to the terminating '\0' Returns the number of characters written (not including the terminating '\0') or -1 on failure.
Definition at line 99 of file buffer.c.
References ldns_struct_buffer::_limit, ldns_struct_buffer::_capacity, vsnprintf(), ldns_struct_buffer::_status, LDNS_STATUS_INTERNAL_ERR, ldns_buffer_reserve(), LDNS_STATUS_MEM_ERR, and ldns_struct_buffer::_position.
void ldns_buffer_free | ( | ldns_buffer * | buffer | ) |
frees the buffer.
[in] | *buffer | the buffer to be freed |
Definition at line 137 of file buffer.c.
References LDNS_FREE, and ldns_struct_buffer::_data.
void* ldns_buffer_export | ( | ldns_buffer * | buffer | ) |
Makes the buffer fixed and returns a pointer to the data.
The caller is responsible for free'ing the result.
[in] | *buffer | the buffer to be exported |
Definition at line 149 of file buffer.c.
References ldns_struct_buffer::_fixed, and ldns_struct_buffer::_data.
int ldns_bgetc | ( | ldns_buffer * | buffer | ) |
returns the next character from a buffer.
Advances the position pointer with 1. When end of buffer is reached returns EOF. This is the buffer's equivalent for getc().
[in] | *buffer | buffer to read from |
Definition at line 156 of file buffer.c.
References ldns_struct_buffer::_position.
void ldns_buffer_copy | ( | ldns_buffer * | result, |
ldns_buffer * | from | ||
) |