Changeset View
Changeset View
Standalone View
Standalone View
contrib/ldns/ldns/buffer.h
Show First 20 Lines • Show All 394 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
INLINE void | INLINE void | ||||
ldns_buffer_write_string(ldns_buffer *buffer, const char *str) | ldns_buffer_write_string(ldns_buffer *buffer, const char *str) | ||||
{ | { | ||||
ldns_buffer_write(buffer, str, strlen(str)); | ldns_buffer_write(buffer, str, strlen(str)); | ||||
} | } | ||||
/** | /** | ||||
* copies the given (null-delimited) string to the current position at the buffer | |||||
* increasing the capacity if necessary | |||||
* \param[in] buffer the buffer | |||||
* \param[in] str the string to write | |||||
*/ | |||||
INLINE void | |||||
ldns_buffer_write_chars(ldns_buffer *buffer, const char *str) | |||||
{ | |||||
if (!ldns_buffer_reserve(buffer, strlen(str))) | |||||
buffer->_status = LDNS_STATUS_MEM_ERR; | |||||
else | |||||
ldns_buffer_write_string(buffer, str); | |||||
} | |||||
/** | |||||
* writes the given byte of data at the given position in the buffer | * writes the given byte of data at the given position in the buffer | ||||
* \param[in] buffer the buffer | * \param[in] buffer the buffer | ||||
* \param[in] at the position in the buffer | * \param[in] at the position in the buffer | ||||
* \param[in] data the 8 bits to write | * \param[in] data the 8 bits to write | ||||
*/ | */ | ||||
INLINE void | INLINE void | ||||
ldns_buffer_write_u8_at(ldns_buffer *buffer, size_t at, uint8_t data) | ldns_buffer_write_u8_at(ldns_buffer *buffer, size_t at, uint8_t data) | ||||
{ | { | ||||
assert(ldns_buffer_available_at(buffer, at, sizeof(data))); | assert(ldns_buffer_available_at(buffer, at, sizeof(data))); | ||||
buffer->_data[at] = data; | buffer->_data[at] = data; | ||||
} | } | ||||
/** | /** | ||||
* writes the given byte of data at the current position in the buffer | * writes the given byte of data at the current position in the buffer | ||||
* \param[in] buffer the buffer | * \param[in] buffer the buffer | ||||
* \param[in] data the 8 bits to write | * \param[in] data the 8 bits to write | ||||
*/ | */ | ||||
INLINE void | INLINE void | ||||
ldns_buffer_write_u8(ldns_buffer *buffer, uint8_t data) | ldns_buffer_write_u8(ldns_buffer *buffer, uint8_t data) | ||||
{ | { | ||||
ldns_buffer_write_u8_at(buffer, buffer->_position, data); | ldns_buffer_write_u8_at(buffer, buffer->_position, data); | ||||
buffer->_position += sizeof(data); | buffer->_position += sizeof(data); | ||||
} | |||||
/** | |||||
* writes the given byte of data at the current position in the buffer | |||||
* increasing the capacity if necessary | |||||
* \param[in] buffer the buffer | |||||
* \param[in] data the 8 bits to write | |||||
*/ | |||||
INLINE void | |||||
ldns_buffer_write_char(ldns_buffer *buffer, uint8_t data) | |||||
{ | |||||
if (!ldns_buffer_reserve(buffer, sizeof(data))) | |||||
buffer->_status = LDNS_STATUS_MEM_ERR; | |||||
else | |||||
ldns_buffer_write_u8(buffer, data); | |||||
} | } | ||||
/** | /** | ||||
* writes the given 2 byte integer at the given position in the buffer | * writes the given 2 byte integer at the given position in the buffer | ||||
* \param[in] buffer the buffer | * \param[in] buffer the buffer | ||||
* \param[in] at the position in the buffer | * \param[in] at the position in the buffer | ||||
* \param[in] data the 16 bits to write | * \param[in] data the 16 bits to write | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 213 Lines • Show Last 20 Lines |