isc_result_t
dns_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);
/*%<
- * Makes 'dest' refer to a copy of the name in 'source'. The data are
- * either copied to 'target' or the dedicated buffer in 'dest'.
+ * Makes 'dest' refer to a copy of the name in 'source'. The data are either
+ * copied to 'target' or in case of dns_name_copyfixed the dedicated buffer in
+ * 'dest'.
*
* Requires:
* \li 'source' is a valid name.
*
* \li 'dest' is an initialized name with a dedicated buffer.
*
- * \li 'target' is NULL or an initialized buffer.
+ * \li 'target' is an initialized buffer.
*
* \li Either dest has a dedicated buffer or target != NULL.
*
return (result);
}
+static
isc_result_t
-dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) {
+name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) {
unsigned char *ndata;
/*
* Make dest a copy of source.
*/
- REQUIRE(VALID_NAME(source));
- REQUIRE(VALID_NAME(dest));
- REQUIRE(target != NULL || dest->buffer != NULL);
-
- if (target == NULL) {
- target = dest->buffer;
- isc_buffer_clear(dest->buffer);
- }
-
REQUIRE(BINDABLE(dest));
/*
* Set up.
*/
- if (target->length - target->used < source->length)
+ if (target->length - target->used < source->length) {
return (ISC_R_NOSPACE);
+ }
ndata = (unsigned char *)target->base + target->used;
dest->ndata = target->base;
- if (source->length != 0)
+ if (source->length != 0) {
memmove(ndata, source->ndata, source->length);
+ }
dest->ndata = ndata;
dest->labels = source->labels;
dest->length = source->length;
- if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0)
+ if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
dest->attributes = DNS_NAMEATTR_ABSOLUTE;
- else
+ } else {
dest->attributes = 0;
+ }
if (dest->labels > 0 && dest->offsets != NULL) {
- if (source->offsets != NULL)
+ if (source->offsets != NULL) {
memmove(dest->offsets, source->offsets, source->labels);
- else
+ } else {
set_offsets(dest, dest->offsets, NULL);
+ }
}
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);
+}
+
void
dns_name_destroy(void) {
RUNTIME_CHECK(isc_once_do(&once, thread_key_mutex_init)