* hb_list_insert ********************************************************************** * Adds an item at the specified position in the list, making it bigger * if necessary. * Can safely be called with a NULL pointer to add, it will be ignored. *********************************************************************/
| 4162 | * Can safely be called with a NULL pointer to add, it will be ignored. |
| 4163 | *********************************************************************/ |
| 4164 | void hb_list_insert( hb_list_t * l, int pos, void * p ) |
| 4165 | { |
| 4166 | if( !p ) |
| 4167 | { |
| 4168 | return; |
| 4169 | } |
| 4170 | |
| 4171 | if( l->items_count == l->items_alloc ) |
| 4172 | { |
| 4173 | /* We need a bigger boat */ |
| 4174 | l->items_alloc += HB_LIST_DEFAULT_SIZE; |
| 4175 | l->items = realloc( l->items, |
| 4176 | l->items_alloc * sizeof( void * ) ); |
| 4177 | } |
| 4178 | |
| 4179 | if ( l->items_count != pos ) |
| 4180 | { |
| 4181 | /* Shift all items after it sizeof( void * ) bytes earlier */ |
| 4182 | memmove( &l->items[pos+1], &l->items[pos], |
| 4183 | ( l->items_count - pos ) * sizeof( void * ) ); |
| 4184 | } |
| 4185 | |
| 4186 | |
| 4187 | l->items[pos] = p; |
| 4188 | (l->items_count)++; |
| 4189 | } |
| 4190 | |
| 4191 | /********************************************************************** |
| 4192 | * hb_list_rem |
no outgoing calls
no test coverage detected