From cae6ddd340bc40475544d020565199b7a357411a Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Wed, 22 Sep 1999 00:35:59 +0000 Subject: [PATCH] add isc_buffer_copyregion --- lib/isc/buffer.c | 18 ++++++++++++++++++ lib/isc/include/isc/buffer.h | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index 0f87b314f3..d3155c11ad 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -384,6 +384,24 @@ isc_buffer_putuint32(isc_buffer_t *b, isc_uint32_t val) 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_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer, unsigned int length, unsigned int type) diff --git a/lib/isc/include/isc/buffer.h b/lib/isc/include/isc/buffer.h index 86f4618f26..08cab0e433 100644 --- a/lib/isc/include/isc/buffer.h +++ b/lib/isc/include/isc/buffer.h @@ -539,6 +539,23 @@ isc_buffer_putuint32(isc_buffer_t *b, isc_uint32_t val); * 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 #endif /* ISC_BUFFER_H */