361 } else { |
361 } else { |
362 return NULL; |
362 return NULL; |
363 } |
363 } |
364 } |
364 } |
365 |
365 |
366 static ssize_t cx_arl_find( |
366 static ssize_t cx_arl_find_remove( |
367 struct cx_list_s const *list, |
367 struct cx_list_s *list, |
368 void const *elem |
368 void const *elem, |
|
369 bool remove |
369 ) { |
370 ) { |
370 assert(list->cmpfunc != NULL); |
371 assert(list->cmpfunc != NULL); |
371 assert(list->size < SIZE_MAX / 2); |
372 assert(list->size < SIZE_MAX / 2); |
372 char *cur = ((cx_array_list const *) list)->data; |
373 char *cur = ((cx_array_list const *) list)->data; |
373 |
374 |
374 for (ssize_t i = 0; i < (ssize_t) list->size; i++) { |
375 for (ssize_t i = 0; i < (ssize_t) list->size; i++) { |
375 if (0 == list->cmpfunc(elem, cur)) { |
376 if (0 == list->cmpfunc(elem, cur)) { |
376 return i; |
377 if (remove) { |
|
378 if (0 == cx_arl_remove(list, i)) { |
|
379 return i; |
|
380 } else { |
|
381 return -1; |
|
382 } |
|
383 } else { |
|
384 return i; |
|
385 } |
377 } |
386 } |
378 cur += list->item_size; |
387 cur += list->item_size; |
379 } |
388 } |
380 |
389 |
381 return -1; |
390 return -1; |