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

Comparing projects/libstatgrab/src/libstatgrab/swap_stats.c (file contents):
Revision 1.7 by ats, Sun Oct 19 02:03:02 2003 UTC vs.
Revision 1.8 by ats, Fri Oct 24 17:26:43 2003 UTC

# Line 31 | Line 31
31   #endif
32   #ifdef LINUX
33   #include <stdio.h>
34 + #include <string.h>
35   #endif
36   #ifdef FREEBSD
37   #include <unistd.h>
# Line 49 | Line 50 | swap_stat_t *get_swap_stats(){
50   #ifdef LINUX
51          FILE *f;
52          char *line_ptr;
53 +        unsigned long long value;
54   #endif
55   #ifdef FREEBSD
56          struct kvm_swap swapinfo;
# Line 71 | Line 73 | swap_stat_t *get_swap_stats(){
73          swap_stat.free = swap_stat.total - swap_stat.used;
74   #endif
75   #ifdef LINUX
76 <        if ((f=fopen("/proc/meminfo", "r" ))==NULL) {
76 >        if ((f = fopen("/proc/meminfo", "r")) == NULL) {
77                  return NULL;
78          }
79 <        if((line_ptr=f_read_line(f, "Swap:"))==NULL){
80 <                fclose(f);
81 <                return NULL;
79 >
80 >        while ((line_ptr = f_read_line(f, "")) != NULL) {
81 >                if (sscanf(line_ptr, "%*s %llu kB", &value) != 1) {
82 >                        continue;
83 >                }
84 >                value *= 1024;
85 >
86 >                if (strncmp(line_ptr, "SwapTotal:", 10) == 0) {
87 >                        swap_stat.total = value;
88 >                } else if (strncmp(line_ptr, "SwapFree:", 9) == 0) {
89 >                        swap_stat.free = value;
90 >                }
91          }
92 <        if((sscanf(line_ptr, "Swap: %lld %lld %lld", &swap_stat.total, &swap_stat.used, &swap_stat.free))!=3){
82 <                fclose(f);
83 <                return NULL;
84 <        }
92 >
93          fclose(f);
94 +        swap_stat.used = swap_stat.total - swap_stat.free;
95   #endif
96   #ifdef FREEBSD
97          if((kvmd = get_kvm()) == NULL){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines