# HG changeset patch # User David Demelier # Date 1327775939 -3600 # Node ID 06c968b920906ecb24780eb4f5df4f68a5cdc98f # Parent eac1f370910a55e55f699aa63b054c84a11b22d2 Use pointer to pointer in array_find, better to reuse diff -r eac1f370910a -r 06c968b92090 array.c --- a/array.c Tue Jan 24 16:26:25 2012 +0100 +++ b/array.c Sat Jan 28 19:38:59 2012 +0100 @@ -271,25 +271,24 @@ /* * Compare each object with the user supplied function. If the `fn' function - * returns 1 then the index of the data position is returned and the parameter - * data is filled with the array data at the correct index. If the comparison - * function nevers returns 1, array_find returns -1. + * returns 1, 1 is returned and dst points to the correct object, dst should + * be a pointer to a pointer of object, like (int **) for a array of int. */ int -array_find(const struct array *arr, array_cmp_fn fn, void *data, void *u) +array_find(const struct array *arr, array_cmp_fn fn, void *dst, void *u) { int st, i; - for (i = st = 0; i < arr->length && st != 1; ++i) + for (i = st = 0; i < arr->length && !st; ++i) st = fn((char *)arr->data + OFFSET(i), u); if (st) - memcpy(data, (char *)arr->data + OFFSET(--i), arr->unit); + *(char **)dst = (char *)arr->data + OFFSET(--i); else - i = -1; + st = 0; - return i; + return st; } /*