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

Comparing projects/libstatgrab/src/libstatgrab/disk_stats.c (file contents):
Revision 1.57 by ats, Sun Apr 4 22:29:54 2004 UTC vs.
Revision 1.59 by ats, Sun Apr 4 23:55:48 2004 UTC

# Line 76 | Line 76
76                          "ntfs"}
77   #endif
78  
79 static char *copy_string(char **dest, const char *src) {
80        char *new;
81
82        new = realloc(*dest, strlen(src) + 1);
83        if (new == NULL) {
84                return NULL;
85        }
86
87        strcpy(new, src);
88        *dest = new;
89        return new;
90 }
91
79   static void disk_stat_init(disk_stat_t *d) {
80          d->device_name = NULL;
81          d->fs_type = NULL;
# Line 178 | Line 165 | disk_stat_t *get_disk_stats(int *entries){
165                          disk_ptr=disk_stats+num_disks;
166  
167   #ifdef ALLBSD
168 <                        if (copy_string(&disk_ptr->device_name, mp->f_mntfromname) == NULL) {
168 >                        if (update_string(&disk_ptr->device_name, mp->f_mntfromname) == NULL) {
169                                  return NULL;
170                          }
171 <                        if (copy_string(&disk_ptr->fs_type, mp->f_fstypename) == NULL) {
171 >                        if (update_string(&disk_ptr->fs_type, mp->f_fstypename) == NULL) {
172                                  return NULL;
173                          }
174 <                        if (copy_string(&disk_ptr->mnt_point, mp->f_mntonname) == NULL) {
174 >                        if (update_string(&disk_ptr->mnt_point, mp->f_mntonname) == NULL) {
175                                  return NULL;
176                          }
177  
# Line 198 | Line 185 | disk_stat_t *get_disk_stats(int *entries){
185                          disk_ptr->used_inodes=disk_ptr->total_inodes-disk_ptr->free_inodes;
186   #endif
187   #if defined(LINUX) || defined(CYGWIN)
188 <                        if (copy_string(&disk_ptr->device_name, mp->mnt_fsname) == NULL) {
188 >                        if (update_string(&disk_ptr->device_name, mp->mnt_fsname) == NULL) {
189                                  return NULL;
190                          }
191                                  
192 <                        if (copy_string(&disk_ptr->fs_type, mp->mnt_type) == NULL) {    
192 >                        if (update_string(&disk_ptr->fs_type, mp->mnt_type) == NULL) {  
193                                  return NULL;
194                          }
195  
196 <                        if (copy_string(&disk_ptr->mnt_point, mp->mnt_dir) == NULL) {
196 >                        if (update_string(&disk_ptr->mnt_point, mp->mnt_dir) == NULL) {
197                                  return NULL;
198                          }
199                          disk_ptr->size = (long long)fs.f_bsize * (long long)fs.f_blocks;
# Line 224 | Line 211 | disk_stat_t *get_disk_stats(int *entries){
211                           * Downside is its a bit hungry for a lot of mounts, as MNT_MAX_SIZE would prob
212                           * be upwards of a k each
213                           */
214 <                        if (copy_string(&disk_ptr->device_name, mp.mnt_special) == NULL) {
214 >                        if (update_string(&disk_ptr->device_name, mp.mnt_special) == NULL) {
215                                  return NULL;
216                          }
217  
218 <                        if (copy_string(&disk_ptr->fs_type, mp.mnt_fstype) == NULL) {
218 >                        if (update_string(&disk_ptr->fs_type, mp.mnt_fstype) == NULL) {
219                                  return NULL;
220                          }
221          
222 <                        if (copy_string(&disk_ptr->mnt_point, mp.mnt_mountp) == NULL) {
222 >                        if (update_string(&disk_ptr->mnt_point, mp.mnt_mountp) == NULL) {
223                                  return NULL;
224                          }
225                          
# Line 297 | Line 284 | diskio_stat_t *get_diskio_stats(int *entries){
284          char *line_ptr;
285          int major, minor;
286          int has_pp_stats = 1;
287 <        static partition *parts = NULL;
301 <        static int alloc_parts = 0;
287 >        VECTOR_DECLARE_STATIC(parts, partition, 16, NULL, NULL);
288          int i, n;
289          time_t now;
290          const char *format;
# Line 575 | Line 561 | diskio_stat_t *get_diskio_stats(int *entries){
561                  if (VECTOR_RESIZE(diskio_stats, n + 1) < 0) {
562                          goto out;
563                  }
564 <                if (n >= alloc_parts) {
565 <                        alloc_parts += 16;
580 <                        parts = realloc(parts, alloc_parts * sizeof *parts);
581 <                        if (parts == NULL) {
582 <                                alloc_parts = 0;
583 <                                goto out;
584 <                        }
564 >                if (VECTOR_RESIZE(parts, n + 1) < 0) {
565 >                        goto out;
566                  }
567  
568                  if (diskio_stats[n].disk_name != NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines