ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/vector.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/vector.c (file contents):
Revision 1.2 by ats, Mon Apr 5 00:20:05 2004 UTC vs.
Revision 1.3 by ats, Mon Apr 5 00:45:17 2004 UTC

# Line 29 | Line 29
29  
30   #include "vector.h"
31  
32 < int statgrab_vector_resize(char **vector, vector_header *h, int count) {
32 > void *statgrab_vector_resize(void *vector, vector_header *h, int count) {
33          int new_count, i;
34  
35          /* Destroy any now-unused items. */
36          if (count < h->used_count && h->destroy_fn != NULL) {
37                  for (i = count; i < h->used_count; i++) {
38 <                        h->destroy_fn((void *) ((*vector) + i * h->item_size));
38 >                        h->destroy_fn((void *) (vector + i * h->item_size));
39                  }
40          }
41  
# Line 47 | Line 47 | int statgrab_vector_resize(char **vector, vector_heade
47          if (new_count != h->alloc_count) {
48                  char *new_vector;
49  
50 <                new_vector = realloc(*vector, new_count * h->item_size);
50 >                new_vector = realloc(vector, new_count * h->item_size);
51                  if (new_vector == NULL && new_count != 0) {
52                          /* Out of memory -- free the contents of the vector. */
53                          statgrab_vector_resize(vector, h, 0);
54 <                        return -1;
54 >                        /* And return the sentinel value to indicate failure. */
55 >                        return statgrab_vector_sentinel;
56                  }
57  
58 <                *vector = new_vector;
58 >                vector = new_vector;
59                  h->alloc_count = new_count;
60          }
61  
62          /* Initialise any new items. */
63          if (count > h->used_count && h->init_fn != NULL) {
64                  for (i = h->used_count; i < count; i++) {
65 <                        h->init_fn((void *) ((*vector) + i * h->item_size));
65 >                        h->init_fn((void *) (vector + i * h->item_size));
66                  }
67          }
68  
69          h->used_count = count;
70  
71 <        return 0;
71 >        return vector;
72   }
73  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines