27 |
|
|
28 |
|
#include <stdlib.h> |
29 |
|
|
30 |
+ |
#include "tools.h" |
31 |
|
#include "vector.h" |
32 |
|
|
33 |
|
void *sg_vector_resize(void *vector, vector_header *h, int count) { |
34 |
|
int new_count, i; |
35 |
|
|
36 |
|
/* Destroy any now-unused items. |
37 |
< |
* |
37 |
> |
* |
38 |
|
* Note that there's an assumption here that making the vector smaller |
39 |
|
* will never fail; if it did, then we would have destroyed items here |
40 |
|
* but not actually got rid of the vector pointing to them before the |
47 |
|
|
48 |
|
/* Round up the desired size to the next multiple of the block size. */ |
49 |
|
new_count = ((count - 1 + h->block_size) / h->block_size) |
50 |
< |
* h->block_size; |
50 |
> |
* h->block_size; |
51 |
|
|
52 |
|
/* Resize the vector if necessary. */ |
53 |
|
if (new_count != h->alloc_count) { |
54 |
|
char *new_vector; |
55 |
|
|
56 |
< |
new_vector = realloc(vector, new_count * h->item_size); |
56 |
> |
new_vector = sg_realloc(vector, new_count * h->item_size); |
57 |
|
if (new_vector == NULL && new_count != 0) { |
58 |
|
/* Out of memory -- free the contents of the vector. */ |
59 |
|
sg_vector_resize(vector, h, 0); |