lib/dns/masterdump.c
/*
 * Print an rdataset.  'buffer' is a scratch buffer, which must have been
 * dynamically allocated by the caller.  It must be large enough to
 * hold the result from dns_ttl_totext().  If more than that is needed,
 * the buffer will be grown automatically.
 */
Print an rdataset.  'buffer' is a scratch buffer, which must have been
dynamically allocated by the caller.  It must be large enough to
hold the result from dns_ttl_totext().  If more than that is needed,
the buffer will be grown automatically.
Print an rdataset . ' buffer ' is a scratch buffer which must have been dynamically allocated by the caller . It must be large enough to hold the result from dns_ttl_totext () . If more than that is needed the buffer will be grown automatically .
static isc_result_t
dump_rdataset(isc_mem_t *mctx, dns_name_t *name, dns_rdataset_t *rdataset,
	      dns_totext_ctx_t *ctx,
	      isc_buffer_t *buffer, FILE *f)
{
	isc_region_t r;
	isc_result_t result;
	REQUIRE(buffer->length > 0);
	if ((ctx->style.flags & DNS_STYLEFLAG_TTL) != 0) {
		if (ctx->current_ttl_valid == ISC_FALSE ||
		    ctx->current_ttl != rdataset->ttl)
		{
			if ((ctx->style.flags & DNS_STYLEFLAG_COMMENT) != 0)
			{
				isc_buffer_clear(buffer);
				result = dns_ttl_totext(rdataset->ttl,
							ISC_TRUE, buffer);
				INSIST(result == ISC_R_SUCCESS);
				isc_buffer_usedregion(buffer, &r);
				fprintf(f, "$TTL %u\t; %.*s\n", rdataset->ttl,
					(int) r.length, (char *) r.base);
			} else {
				fprintf(f, "$TTL %u\n", rdataset->ttl);
			}
			ctx->current_ttl = rdataset->ttl;
			ctx->current_ttl_valid = ISC_TRUE;
		}
	}
	isc_buffer_clear(buffer);
	for (;;) {
		int newlength;
		void *newmem;
		result = rdataset_totext(rdataset, name, ctx,
					 ISC_FALSE, buffer);
		if (result != ISC_R_NOSPACE)
			break;
		newlength = buffer->length * 2;
		newmem = isc_mem_get(mctx, newlength);
		if (newmem == NULL)
			return (ISC_R_NOMEMORY);
		isc_mem_put(mctx, buffer->base, buffer->length);
		isc_buffer_init(buffer, newmem, newlength);
	}
	if (result != ISC_R_SUCCESS)
		return (result);
	isc_buffer_usedregion(buffer, &r);
	result = isc_stdio_write(r.base, 1, (size_t)r.length, f, NULL);
	if (result != ISC_R_SUCCESS) {
		UNEXPECTED_ERROR(__FILE__, __LINE__,
				 "master file write failed: %s",
				 isc_result_totext(result));
		return (result);
	}
	return (ISC_R_SUCCESS);
}
static isc_result_t dump_rdataset ( isc_mem_t * mctx , dns_name_t * name , dns_rdataset_t * rdataset , dns_totext_ctx_t * ctx , isc_buffer_t * buffer , FILE * f ) { isc_region_t r ; isc_result_t result ; REQUIRE ( buffer -> length > 0 ) ; if ( ( ctx -> style . flags & DNS_STYLEFLAG_TTL ) != 0 ) { if ( ctx -> current_ttl_valid == ISC_FALSE || ctx -> current_ttl != rdataset -> ttl ) { if ( ( ctx -> style . flags & DNS_STYLEFLAG_COMMENT ) != 0 ) { isc_buffer_clear ( buffer ) ; result = dns_ttl_totext ( rdataset -> ttl , ISC_TRUE , buffer ) ; INSIST ( result == ISC_R_SUCCESS ) ; isc_buffer_usedregion ( buffer , & r ) ; fprintf ( f , " \t \n " , rdataset -> ttl , ( int ) r . length , ( char * ) r . base ) ; } else { fprintf ( f , " \n " , rdataset -> ttl ) ; } ctx -> current_ttl = rdataset -> ttl ; ctx -> current_ttl_valid = ISC_TRUE ; } } isc_buffer_clear ( buffer ) ; for ( ; ; ) { int newlength ; void * newmem ; result = rdataset_totext ( rdataset , name , ctx , ISC_FALSE , buffer ) ; if ( result != ISC_R_NOSPACE ) break ; newlength = buffer -> length * 2 ; newmem = isc_mem_get ( mctx , newlength ) ; if ( newmem == NULL ) return ( ISC_R_NOMEMORY ) ; isc_mem_put ( mctx , buffer -> base , buffer -> length ) ; isc_buffer_init ( buffer , newmem , newlength ) ; } if ( result != ISC_R_SUCCESS ) return ( result ) ; isc_buffer_usedregion ( buffer , & r ) ; result = isc_stdio_write ( r . base , 1 , ( size_t ) r . length , f , NULL ) ; if ( result != ISC_R_SUCCESS ) { UNEXPECTED_ERROR ( __FILE__ , __LINE__ , " " , isc_result_totext ( result ) ) ; return ( result ) ; } return ( ISC_R_SUCCESS ) ; }
Print an rdataset.
Print an rdataset .
/*
	 * Output a $TTL directive if needed.
	 */ /*
	 * Generate the text representation of the rdataset into
	 * the buffer.  If the buffer is too small, grow it.
	 */ /*
	 * Write the buffer contents to the master file.
	 */