library/src/datastructures/BP-LinkedList.cc
BP_ERROR_T BP_LinkLFlattenJoinStringElements(P_BP_LINKL head)
{

	// ensure we have a head
	if(!head)
		return ERR_FAILURE;

	// destroy flattened data if it already exists
	if(head->flat_buff)
	{
		bpfree(head->flat_buff);
		head->flat_buff_n = 0;
		head->flat_buff   = NULL;
	}

	// ensure the list has a total size
	if(!head->total_size)
		return ERR_FAILURE;

	// attempt to get the first item
	P_BP_LINKL_DATA first_item = TAILQ_FIRST(&head->head);

	// ensure we have a first item
	if(!first_item)
		return ERR_FAILURE;

	// current position, used for writing data to the string
	size_t current_pos = 0;

	// inner iterator for data
	size_t n = 0;

	// allocate space for the buffer (+1 for mandatory null termination)
	head->flat_buff   = (unsigned char *) bpcalloc(head->total_size+1, 1);
	head->flat_buff_n = head->total_size;

	// since void has no type, we need a temporary data pointer
	unsigned char * data = NULL;

	// looks for a pointer in the item
	TAILQ_FOREACH(first_item, &head->head, linkl_data)
	{

		// ensure we have a string chunk
		if(
			(first_item->data_type == BP_MEMPROF_ALLOC_TYPE_STRDUP)  ||
			(first_item->data_type == BP_MEMPROF_ALLOC_TYPE_STRNDUP) ||
			(first_item->data_type == BP_MEMPROF_ALLOC_TYPE_USER_DEFINED_ASCII)
		)
		{

			// set temporary pointer
			data = (unsigned char *) first_item->data;

			// now write the buffer into position
			for(n=0; n < (strnlen((char *) first_item->data, first_item->data_size)); n++)
			{

				head->flat_buff[current_pos] = (unsigned char) data[n];
				current_pos++;

	 		}

		}

	}

	// return indicating success
	return ERR_SUCCESS;

}
// This flattens the the linkl string elements into a
// joined single string.  It removes the null terminators
// from existing strings when joining.  If you want to
// flatten raw data, use the raw version.
This flattens the the linkl string elements into a
joined single string.  It removes the null terminators
from existing strings when joining.  If you want to
flatten raw data, use the raw version.
This flattens the the linkl string elements into a joined single string . It removes the null terminators from existing strings when joining . If you want to flatten raw data use the raw version .
BP_ERROR_T BP_LinkLFlattenJoinStringElements(P_BP_LINKL head)
{
	if(!head)
		return ERR_FAILURE;
	if(head->flat_buff)
	{
		bpfree(head->flat_buff);
		head->flat_buff_n = 0;
		head->flat_buff   = NULL;
	}
	if(!head->total_size)
		return ERR_FAILURE;
	P_BP_LINKL_DATA first_item = TAILQ_FIRST(&head->head);
	if(!first_item)
		return ERR_FAILURE;
	size_t current_pos = 0;
	size_t n = 0;
	head->flat_buff   = (unsigned char *) bpcalloc(head->total_size+1, 1);
	head->flat_buff_n = head->total_size;
	unsigned char * data = NULL;
	TAILQ_FOREACH(first_item, &head->head, linkl_data)
	{
		if(
			(first_item->data_type == BP_MEMPROF_ALLOC_TYPE_STRDUP)  ||
			(first_item->data_type == BP_MEMPROF_ALLOC_TYPE_STRNDUP) ||
			(first_item->data_type == BP_MEMPROF_ALLOC_TYPE_USER_DEFINED_ASCII)
		)
		{
			data = (unsigned char *) first_item->data;
			for(n=0; n < (strnlen((char *) first_item->data, first_item->data_size)); n++)
			{
				head->flat_buff[current_pos] = (unsigned char) data[n];
				current_pos++;
	 		}
		}
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_LinkLFlattenJoinStringElements ( P_BP_LINKL head ) { if ( ! head ) return ERR_FAILURE ; if ( head -> flat_buff ) { bpfree ( head -> flat_buff ) ; head -> flat_buff_n = 0 ; head -> flat_buff = NULL ; } if ( ! head -> total_size ) return ERR_FAILURE ; P_BP_LINKL_DATA first_item = TAILQ_FIRST ( & head -> head ) ; if ( ! first_item ) return ERR_FAILURE ; size_t current_pos = 0 ; size_t n = 0 ; head -> flat_buff = ( unsigned char * ) bpcalloc ( head -> total_size + 1 , 1 ) ; head -> flat_buff_n = head -> total_size ; unsigned char * data = NULL ; TAILQ_FOREACH ( first_item , & head -> head , linkl_data ) { if ( ( first_item -> data_type == BP_MEMPROF_ALLOC_TYPE_STRDUP ) || ( first_item -> data_type == BP_MEMPROF_ALLOC_TYPE_STRNDUP ) || ( first_item -> data_type == BP_MEMPROF_ALLOC_TYPE_USER_DEFINED_ASCII ) ) { data = ( unsigned char * ) first_item -> data ; for ( n = 0 ; n < ( strnlen ( ( char * ) first_item -> data , first_item -> data_size ) ) ; n ++ ) { head -> flat_buff [ current_pos ] = ( unsigned char ) data [ n ] ; current_pos ++ ; } } } return ERR_SUCCESS ; }
This flattens the the linkl string elements into a
joined single string.
This flattens the the linkl string elements into a joined single string .
// ensure we have a head // destroy flattened data if it already exists // ensure the list has a total size // attempt to get the first item // ensure we have a first item // current position, used for writing data to the string // inner iterator for data // allocate space for the buffer (+1 for mandatory null termination) // since void has no type, we need a temporary data pointer // looks for a pointer in the item // ensure we have a string chunk // set temporary pointer // now write the buffer into position // return indicating success