* Includes space for the terminating NULL.
*/
-isc_result_t
-dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target);
-/*%<
- * Copies the name in 'source' into 'dest'. The name data is copied to
- * the 'target' buffer, which is then set as the buffer for 'dest'.
- *
- * Requires:
- * \li 'source' is a valid name.
- *
- * \li 'dest' is an initialized name.
- *
- * \li 'target' is an initialized buffer.
- *
- * Ensures:
- *
- *\li On success, the used space in target is updated.
- *
- * Returns:
- *\li #ISC_R_SUCCESS
- *\li #ISC_R_NOSPACE
- */
-
void
dns_name_copynf(const dns_name_t *source, dns_name_t *dest);
/*%<
* Copies the name in 'source' into 'dest'. The name data is copied to
- * the dedicated buffer for 'dest'.
+ * the dedicated buffer for 'dest'. (If copying to a name that doesn't
+ * have a dedicated buffer, use dns_name_setbuffer() first.)
*
* Requires:
* \li 'source' is a valid name.
return (result);
}
-static isc_result_t
-name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) {
+void
+dns_name_copynf(const dns_name_t *source, dns_name_t *dest) {
+ isc_buffer_t *target = NULL;
unsigned char *ndata = NULL;
- /*
- * Make dest a copy of source.
- */
-
+ REQUIRE(VALID_NAME(source));
+ REQUIRE(VALID_NAME(dest));
REQUIRE(BINDABLE(dest));
- /*
- * Set up.
- */
- if (target->length - target->used < source->length) {
- return (ISC_R_NOSPACE);
- }
+ target = dest->buffer;
- ndata = (unsigned char *)target->base + target->used;
+ REQUIRE(target != NULL);
+ REQUIRE(target->length >= source->length);
+
+ isc_buffer_clear(target);
+
+ ndata = (unsigned char *)target->base;
dest->ndata = target->base;
if (source->length != 0) {
}
isc_buffer_add(target, dest->length);
-
- return (ISC_R_SUCCESS);
-}
-
-isc_result_t
-dns_name_copy(const dns_name_t *source, dns_name_t *dest,
- isc_buffer_t *target) {
- REQUIRE(VALID_NAME(source));
- REQUIRE(VALID_NAME(dest));
- REQUIRE(target != NULL);
-
- return (name_copy(source, dest, target));
-}
-
-void
-dns_name_copynf(const dns_name_t *source, dns_name_t *dest) {
- REQUIRE(VALID_NAME(source));
- REQUIRE(VALID_NAME(dest));
- REQUIRE(dest->buffer != NULL);
-
- isc_buffer_clear(dest->buffer);
- RUNTIME_CHECK(name_copy(source, dest, dest->buffer) == ISC_R_SUCCESS);
}
/*