library/src/datastructures/BP-HashTable.cc
char * ht_strndup_real
(
		P_BP_HASH_TABLE_REGISTRY hreg,
		char * dup,
		size_t len,
		BPLN_PARMS
)
{

	// macro to override hreg on null
	BP_GLOBAL_HASH_TABLE_OVERRIDE(NULL);

	// ensure we have a registry
	if(!hreg)
		return NULL;

	// enter critical section
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(hreg);

	// ensure we have a registry to alloc from
	if(!hreg)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);

	// ensure we have a string to dup
	if(!dup)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);

	// ensure we can calc length without faulting
	size_t str_len = bpstrlen(dup);
	if(!str_len)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);

	// this is the calculated final size for allocation
	size_t final_len = 0;

	// calculate final length based around user specified
	// length limitation.  Also shrink buffer if it's smaller
	// than the maximum (saves memory)
	if(str_len >= len)
		final_len = len;
	else
		final_len = str_len;

	// run basic string checks (newlines/cr ok)
	if(!BP_StringIsReasonablePrintableString(dup, final_len, BP_TRUE, BP_TRUE))
	{
	 	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	}

	// attempt to allocate the entry within the hash registry
	char * new_string = (char *) BP_HashRegAddMemoryEntry
	(
			hreg,
			BP_HASH_REG_MEM_ENTRY_TYPE_GENERIC_ALLOCATION,
			final_len+1,
			BPLN_PARMS_PASSTHROUGH
	);

	// copy in the string
	if(new_string)
		memcpy(new_string, dup, final_len);

	// exit if we haven't allocated a new string
	if(!new_string)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);

	// leave critical section
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION(hreg);

	// return indicating success
	return new_string;

}
// duplicates a string and stores it in the hash table
duplicates a string and stores it in the hash table
duplicates a string and stores it in the hash table
char * ht_strndup_real
(
		P_BP_HASH_TABLE_REGISTRY hreg,
		char * dup,
		size_t len,
		BPLN_PARMS
)
{
	BP_GLOBAL_HASH_TABLE_OVERRIDE(NULL);
	if(!hreg)
		return NULL;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(hreg);
	 to alloc from
	if(!hreg)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	if(!dup)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	size_t str_len = bpstrlen(dup);
	if(!str_len)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	size_t final_len = 0;
	if(str_len >= len)
		final_len = len;
	else
		final_len = str_len;
	if(!BP_StringIsReasonablePrintableString(dup, final_len, BP_TRUE, BP_TRUE))
	{
	 	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	}
	char * new_string = (char *) BP_HashRegAddMemoryEntry
	(
			hreg,
			BP_HASH_REG_MEM_ENTRY_TYPE_GENERIC_ALLOCATION,
			final_len+1,
			BPLN_PARMS_PASSTHROUGH
	);
	if(new_string)
		memcpy(new_string, dup, final_len);
	if(!new_string)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION(hreg);
	return new_string;
}
char * ht_strndup_real ( P_BP_HASH_TABLE_REGISTRY hreg , char * dup , size_t len , BPLN_PARMS ) { BP_GLOBAL_HASH_TABLE_OVERRIDE ( NULL ) ; if ( ! hreg ) return NULL ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( hreg ) ; if ( ! hreg ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( hreg , NULL ) ; if ( ! dup ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( hreg , NULL ) ; size_t str_len = bpstrlen ( dup ) ; if ( ! str_len ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( hreg , NULL ) ; size_t final_len = 0 ; if ( str_len >= len ) final_len = len ; else final_len = str_len ; if ( ! BP_StringIsReasonablePrintableString ( dup , final_len , BP_TRUE , BP_TRUE ) ) { BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( hreg , NULL ) ; } char * new_string = ( char * ) BP_HashRegAddMemoryEntry ( hreg , BP_HASH_REG_MEM_ENTRY_TYPE_GENERIC_ALLOCATION , final_len + 1 , BPLN_PARMS_PASSTHROUGH ) ; if ( new_string ) memcpy ( new_string , dup , final_len ) ; if ( ! new_string ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( hreg , NULL ) ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION ( hreg ) ; return new_string ; }
duplicates a string and stores it in the hash table
duplicates a string and stores it in the hash table
// macro to override hreg on null // ensure we have a registry // enter critical section // ensure we have a registry to alloc from // ensure we have a string to dup // ensure we can calc length without faulting // this is the calculated final size for allocation // calculate final length based around user specified // length limitation.  Also shrink buffer if it's smaller // than the maximum (saves memory) // run basic string checks (newlines/cr ok) // attempt to allocate the entry within the hash registry // copy in the string // exit if we haven't allocated a new string // leave critical section // return indicating success