contrib/ldns/host2str.c
char *
ldns_buffer2str(ldns_buffer *buffer)
{
	char *tmp_str;
	char *str;

	/* check if buffer ends with \0, if not, and
	   if there is space, add it */
	if (*(ldns_buffer_at(buffer, ldns_buffer_position(buffer))) != 0) {
		if (!ldns_buffer_reserve(buffer, 1)) {
			return NULL;
		}
		ldns_buffer_write_u8(buffer, (uint8_t) '\0');
		if (!ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer))) {
			return NULL;
		}
	}

	tmp_str = ldns_buffer_export(buffer);
	str = LDNS_XMALLOC(char, strlen(tmp_str) + 1);
        if(!str) {
                return NULL;
        }
	memcpy(str, tmp_str, strlen(tmp_str) + 1);

	return str;
}
/*
 * Zero terminate the buffer and fix it to the size of the string.
 */
Zero terminate the buffer and fix it to the size of the string.
Zero terminate the buffer and fix it to the size of the string .
char *
ldns_buffer2str(ldns_buffer *buffer)
{
	char *tmp_str;
	char *str;
	if (*(ldns_buffer_at(buffer, ldns_buffer_position(buffer))) != 0) {
		if (!ldns_buffer_reserve(buffer, 1)) {
			return NULL;
		}
		ldns_buffer_write_u8(buffer, (uint8_t) '\0');
		if (!ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer))) {
			return NULL;
		}
	}
	tmp_str = ldns_buffer_export(buffer);
	str = LDNS_XMALLOC(char, strlen(tmp_str) + 1);
        if(!str) {
                return NULL;
        }
	memcpy(str, tmp_str, strlen(tmp_str) + 1);
	return str;
}
char * ldns_buffer2str ( ldns_buffer * buffer ) { char * tmp_str ; char * str ; if ( * ( ldns_buffer_at ( buffer , ldns_buffer_position ( buffer ) ) ) != 0 ) { if ( ! ldns_buffer_reserve ( buffer , 1 ) ) { return NULL ; } ldns_buffer_write_u8 ( buffer , ( uint8_t ) ' \0 ' ) ; if ( ! ldns_buffer_set_capacity ( buffer , ldns_buffer_position ( buffer ) ) ) { return NULL ; } } tmp_str = ldns_buffer_export ( buffer ) ; str = LDNS_XMALLOC ( char , strlen ( tmp_str ) + 1 ) ; if ( ! str ) { return NULL ; } memcpy ( str , tmp_str , strlen ( tmp_str ) + 1 ) ; return str ; }
Zero terminate the buffer and fix it to the size of the string.
Zero terminate the buffer and fix it to the size of the string .
/* check if buffer ends with \0, if not, and
	   if there is space, add it */