Commit cae6ddd3 authored by Bob Halley's avatar Bob Halley
Browse files

add isc_buffer_copyregion

parent cdf3c727
...@@ -384,6 +384,24 @@ isc_buffer_putuint32(isc_buffer_t *b, isc_uint32_t val) ...@@ -384,6 +384,24 @@ isc_buffer_putuint32(isc_buffer_t *b, isc_uint32_t val)
cp[3] = (val & 0x000000ff); cp[3] = (val & 0x000000ff);
} }
isc_result_t
isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r) {
unsigned char *base;
unsigned int available;
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(r != NULL);
base = (unsigned char *)b->base + b->used;
available = b->length - b->used;
if (r->length > available)
return (ISC_R_NOSPACE);
memcpy(base, r->base, r->length);
b->used += r->length;
return (ISC_R_SUCCESS);
}
isc_result_t isc_result_t
isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer, isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
unsigned int length, unsigned int type) unsigned int length, unsigned int type)
......
...@@ -539,6 +539,23 @@ isc_buffer_putuint32(isc_buffer_t *b, isc_uint32_t val); ...@@ -539,6 +539,23 @@ isc_buffer_putuint32(isc_buffer_t *b, isc_uint32_t val);
* The used pointer in 'b' is advanced by 4. * The used pointer in 'b' is advanced by 4.
*/ */
isc_result_t
isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r);
/*
* Copy the contents of 'r' into 'b'.
*
* Requires:
* 'b' is a valid buffer.
*
* 'r' is a valid region.
*
* Returns:
*
* ISC_R_SUCCESS
* ISC_R_NOSPACE The available region of 'b' is not
* big enough.
*/
ISC_LANG_ENDDECLS ISC_LANG_ENDDECLS
#endif /* ISC_BUFFER_H */ #endif /* ISC_BUFFER_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment