library/src/utility/BP-StringUtilities.cc
// Generates a hexidecimal string representation of a buffer provided.  Uses
// the supplied tail queue allocator if one is passed in.  If the passed tail
// queue allocator is null, this function uses standard allocation routines to generate
// the buffer, which implies they must be freed directly after use.
Generates a hexidecimal string representation of a buffer provided.  Uses
the supplied tail queue allocator if one is passed in.  If the passed tail
queue allocator is null, this function uses standard allocation routines to generate
the buffer, which implies they must be freed directly after use.
Generates a hexidecimal string representation of a buffer provided . Uses the supplied tail queue allocator if one is passed in . If the passed tail queue allocator is null this function uses standard allocation routines to generate the buffer which implies they must be freed directly after use .
char * BP_GenHexStringFromBuffer(unsigned char * buff, size_t size, P_BP_LINKL tq)
{
	if(!buff || !size)
		return NULL;
	size_t buff_size = (size * 2) + 1;
	char *out_buff = (char *) NULL;
	if(tq)
		out_buff = (char *) tq_calloc(tq, buff_size, 1, BPLN);
	else
		out_buff = (char *) bpcalloc(buff_size, 1);
	size_t n = 0;
	for(; n < size; n++)
	{
		sprintf(&out_buff[n*2], "%.02x", buff[n]);
	}
	if(out_buff && tq)
	{
		P_BP_LINKL_DATA linkl_data = BP_BackwardLookupDataItemFromPointer(tq, out_buff);
		linkl_data->data_type = BP_MEMPROF_ALLOC_TYPE_USER_DEFINED_ASCII;
	}
	return out_buff;
}
char * BP_GenHexStringFromBuffer ( unsigned char * buff , size_t size , P_BP_LINKL tq ) { if ( ! buff || ! size ) return NULL ; size_t buff_size = ( size * 2 ) + 1 ; char * out_buff = ( char * ) NULL ; if ( tq ) out_buff = ( char * ) tq_calloc ( tq , buff_size , 1 , BPLN ) ; else out_buff = ( char * ) bpcalloc ( buff_size , 1 ) ; size_t n = 0 ; for ( ; n < size ; n ++ ) { sprintf ( & out_buff [ n * 2 ] , " " , buff [ n ] ) ; } if ( out_buff && tq ) { P_BP_LINKL_DATA linkl_data = BP_BackwardLookupDataItemFromPointer ( tq , out_buff ) ; linkl_data -> data_type = BP_MEMPROF_ALLOC_TYPE_USER_DEFINED_ASCII ; } return out_buff ; }
Generates a hexidecimal string representation of a buffer provided.
Generates a hexidecimal string representation of a buffer provided .
// check to ensure we have a buffer and a buffer size // since we're expanding the buffer from one byte per char to // two bytes per hex char, we can just multiply size to get // the correct buffer size. // now allocate the out buffer // now fill the buffer with hex data // set data type via manual means since we're creating a string // set the data type here // return the allocated buffer