library/src/datastructures/BP-LinkedList.cc
// attempts to search all elements for a string
attempts to search all elements for a string
attempts to search all elements for a string
char * BP_LinkLSearchForString(P_BP_LINKL head, char *search_string, size_t search_string_len)
{
	if(!head)
		return NULL;
	if(!search_string)
		return NULL;
	if(!search_string_len)
		return NULL;
	P_BP_LINKL_DATA first_item = TAILQ_FIRST(&head->head);
	if(!first_item)
		return 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
		)
		{
			continue;
		}
		if(bpstrlen(search_string) != bpstrlen((char *) first_item->data))
			continue;
		if(memcmp((void *) first_item->data, (void *) search_string, search_string_len) == 0)
			return (char *) first_item->data;
	}
	return NULL;
}
char * BP_LinkLSearchForString ( P_BP_LINKL head , char * search_string , size_t search_string_len ) { if ( ! head ) return NULL ; if ( ! search_string ) return NULL ; if ( ! search_string_len ) return NULL ; P_BP_LINKL_DATA first_item = TAILQ_FIRST ( & head -> head ) ; if ( ! first_item ) return 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 ) { continue ; } if ( bpstrlen ( search_string ) != bpstrlen ( ( char * ) first_item -> data ) ) continue ; if ( memcmp ( ( void * ) first_item -> data , ( void * ) search_string , search_string_len ) == 0 ) return ( char * ) first_item -> data ; } return NULL ; }
attempts to search all elements for a string
attempts to search all elements for a string
// run checks // attempt to get the first item // ensure we have a first item // looks for a pointer in the item // only work with strndup/strdup types // ensure lengths match // if the strings match, return the data // return null if we can't find the string