From 8a21ac0f095f6379d00805a1efa156bbd6790ab3 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 13 Dec 1999 02:18:02 +0000 Subject: [PATCH] Add isc_buffer_putstr(). --- lib/isc/buffer.c | 17 +++++++++++++++++ lib/isc/include/isc/buffer.h | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index dc272b047e..3ad36f2c47 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -397,6 +397,23 @@ isc_buffer_putmem(isc_buffer_t *b, unsigned char *base, unsigned int length) b->used += length; } +isc_result_t +isc_buffer_putstr(isc_buffer_t *b, const char *source) { + unsigned int l; + isc_region_t region; + + REQUIRE(ISC_BUFFER_VALID(b)); + REQUIRE(source != NULL); + + l = strlen(source); + if (l > (b->length - b->used)) + return (ISC_R_NOSPACE); + + memcpy(b->base + b->used, source, l); + b->used += l; + return (ISC_R_SUCCESS); +} + isc_result_t isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r) { unsigned char *base; diff --git a/lib/isc/include/isc/buffer.h b/lib/isc/include/isc/buffer.h index 1558e5447d..a98bd44509 100644 --- a/lib/isc/include/isc/buffer.h +++ b/lib/isc/include/isc/buffer.h @@ -549,6 +549,18 @@ isc_buffer_putmem(isc_buffer_t *b, unsigned char *base, unsigned int length); * * 'base' points to 'length' bytes of valid memory. * + */ + +isc_result_t +isc_buffer_putstr(isc_buffer_t *b, const char *source); +/* + * Copy 'length' bytes of memory at 'base' into 'b'. + * + * Requires: + * 'b' is a valid buffer. + * + * 'source' to be a valid NULL terminated string. + * * Returns: * * ISC_R_SUCCESS