comparison parray.c @ 165:970e491d93cb

Add _trim function to realloc to the needed size
author David Demelier <markand@malikania.fr>
date Mon, 24 Sep 2012 23:03:50 +0200
parents 66d317ba4b80
children
comparison
equal deleted inserted replaced
164:654f32079cdc 165:970e491d93cb
323 arr->data = NULL; 323 arr->data = NULL;
324 arr->size = 0; 324 arr->size = 0;
325 } 325 }
326 326
327 /* 327 /*
328 * Trim down the array to the correct size.
329 */
330 void *
331 parray_trim(struct parray *arr)
332 {
333 int count = arr->length;
334
335 if (arr->flags & PARRAY_NULLEND)
336 ++ count;
337
338 return arr->realloc(arr->data, count * sizeof (void *));
339 }
340
341 /*
328 * Increate the array storage when it is full. If the buffer is fixed size 342 * Increate the array storage when it is full. If the buffer is fixed size
329 * it returns -1 on full buffer otherwise 0 is returned if allocation 343 * it returns -1 on full buffer otherwise 0 is returned if allocation
330 * succeeded. 344 * succeeded.
331 */ 345 */
332 static int 346 static int