35 ldns_buffer_invariant(buffer);
53 memcpy(buffer->
_data, data, size);
56 ldns_buffer_invariant(buffer);
64 ldns_buffer_invariant(buffer);
82 ldns_buffer_invariant(buffer);
84 size_t new_capacity = buffer->
_capacity * 3 / 2;
86 if (new_capacity < buffer->_position + amount) {
87 new_capacity = buffer->
_position + amount;
105 if (ldns_buffer_status_ok(buffer)) {
106 ldns_buffer_invariant(buffer);
109 remaining = ldns_buffer_remaining(buffer);
110 va_start(args, format);
111 written = vsnprintf((
char *) ldns_buffer_current(buffer), remaining,
117 }
else if ((
size_t) written >= remaining) {
122 va_start(args, format);
123 written = vsnprintf((
char *) ldns_buffer_current(buffer),
124 ldns_buffer_remaining(buffer), format, args);
153 return buffer->
_data;
159 if (!ldns_buffer_available_at(buffer, buffer->
_position,
sizeof(uint8_t))) {
160 ldns_buffer_set_position(buffer, ldns_buffer_limit(buffer));
164 return (
int)ldns_buffer_read_u8(buffer);
170 size_t tocopy = ldns_buffer_limit(from);
172 if(tocopy > ldns_buffer_capacity(result))
173 tocopy = ldns_buffer_capacity(result);
174 ldns_buffer_clear(result);
175 ldns_buffer_write(result, ldns_buffer_begin(from), tocopy);
176 ldns_buffer_flip(result);
void ldns_buffer_free(ldns_buffer *buffer)
frees the buffer.
void ldns_buffer_copy(ldns_buffer *result, const ldns_buffer *from)
Copy contents of the from buffer to the result buffer and then flips the result buffer.
signed char ldns_buffer_set_capacity(ldns_buffer *buffer, size_t capacity)
changes the buffer's capacity.
signed char ldns_buffer_reserve(ldns_buffer *buffer, size_t amount)
ensures BUFFER can contain at least AMOUNT more bytes.
int ldns_bgetc(ldns_buffer *buffer)
returns the next character from a buffer.
ldns_buffer * ldns_buffer_new(size_t capacity)
creates a new buffer with the specified capacity.
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_new_frm_data(ldns_buffer *buffer, const void *data, size_t size)
creates a buffer with the specified data.
void * ldns_buffer_export(ldns_buffer *buffer)
Makes the buffer fixed and returns a pointer to the data.
This file contains the definition of ldns_buffer, and functions to manipulate those.
@ LDNS_STATUS_INTERNAL_ERR
Including this file will include all ldns files, and define some lookup tables.
implementation of buffers to ease operations
size_t _capacity
The amount of data the buffer can contain.
unsigned _fixed
If the buffer is fixed it cannot be resized.
size_t _position
The current position used for reading/writing.
ldns_status _status
The current state of the buffer.
uint8_t * _data
The data contained in the buffer.
size_t _limit
The read/write limit.
#define LDNS_MALLOC(type)
Memory management macros.
#define LDNS_XMALLOC(type, count)
#define LDNS_XREALLOC(ptr, type, count)