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.3 by ats, Mon Apr 5 00:45:17 2004 UTC vs.
Revision 1.8 by ats, Wed Apr 7 14:36:36 2004 UTC

# Line 1 | Line 1
1   /*
2 < * i-scream central monitoring system
2 > * i-scream libstatgrab
3   * http://www.i-scream.org
4   * Copyright (C) 2000-2004 i-scream
5   *
# Line 27 | Line 27
27  
28   #include <stdlib.h>
29  
30 + #include "tools.h"
31   #include "vector.h"
32  
33 < void *statgrab_vector_resize(void *vector, vector_header *h, int count) {
33 > void *sg_vector_resize(void *vector, vector_header *h, int count) {
34          int new_count, i;
35  
36 <        /* Destroy any now-unused items. */
36 >        /* Destroy any now-unused items.
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
41 >         * error return.) */
42          if (count < h->used_count && h->destroy_fn != NULL) {
43                  for (i = count; i < h->used_count; i++) {
44                          h->destroy_fn((void *) (vector + i * h->item_size));
# Line 47 | Line 53 | void *statgrab_vector_resize(void *vector, vector_head
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 <                        statgrab_vector_resize(vector, h, 0);
60 <                        /* And return the sentinel value to indicate failure. */
61 <                        return statgrab_vector_sentinel;
59 >                        sg_vector_resize(vector, h, 0);
60 >                        h->error = -1;
61 >                        return vector;
62                  }
63  
64                  vector = new_vector;
# Line 67 | Line 73 | void *statgrab_vector_resize(void *vector, vector_head
73          }
74  
75          h->used_count = count;
76 <
76 >        h->error = 0;
77          return vector;
78   }
79  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines