summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mbbsd/osdep.c63
1 files changed, 32 insertions, 31 deletions
diff --git a/mbbsd/osdep.c b/mbbsd/osdep.c
index 967a4db0..5f99da22 100644
--- a/mbbsd/osdep.c
+++ b/mbbsd/osdep.c
@@ -1,20 +1,19 @@
-/* $Id: osdep.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */
+/* $Id: osdep.c,v 1.2 2002/05/15 09:14:24 ptt Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
-#if defined(linux)
+#if __FreeBSD__
+
+#include <kvm.h>
+
int cpuload(char *str) {
double l[3] = {-1, -1, -1};
- FILE *fp;
+ if(getloadavg(l, 3) != 3)
+ l[0] = -1;
- if((fp = fopen("/proc/loadavg", "r"))) {
- if(fscanf(fp, "%lf %lf %lf", &l[0], &l[1], &l[2]) != 3)
- l[0] = -1;
- fclose(fp);
- }
if(str) {
if(l[0] != -1)
sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]);
@@ -26,28 +25,34 @@ int cpuload(char *str) {
double swapused(long *total, long *used) {
double percent = -1;
- char buf[101];
- FILE *fp;
+ kvm_t *kd;
+ struct kvm_swap swapinfo;
+ int pagesize;
- if((fp = fopen("/proc/meminfo","r"))) {
- while(fgets(buf, 100, fp) && buf[0] != 'S');
- if(sscanf(buf + 6, "%ld %ld", total, used) == 2)
+ kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
+ if(kd) {
+ if(kvm_getswapinfo(kd, &swapinfo, 1, 0) == 0) {
+ pagesize = getpagesize();
+ *total = swapinfo.ksw_total * pagesize;
+ *used = swapinfo.ksw_used * pagesize;
if(*total != 0)
percent = (double)*used / (double)*total;
- fclose(fp);
+ }
+ kvm_close(kd);
}
return percent;
}
-#elif __FreeBSD__ >=4
-
-#include <kvm.h>
-
+#else
int cpuload(char *str) {
double l[3] = {-1, -1, -1};
- if(getloadavg(l, 3) != 3)
- l[0] = -1;
+ FILE *fp;
+ if((fp = fopen("/proc/loadavg", "r"))) {
+ if(fscanf(fp, "%lf %lf %lf", &l[0], &l[1], &l[2]) != 3)
+ l[0] = -1;
+ fclose(fp);
+ }
if(str) {
if(l[0] != -1)
sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]);
@@ -59,21 +64,17 @@ int cpuload(char *str) {
double swapused(long *total, long *used) {
double percent = -1;
- kvm_t *kd;
- struct kvm_swap swapinfo;
- int pagesize;
+ char buf[101];
+ FILE *fp;
- kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
- if(kd) {
- if(kvm_getswapinfo(kd, &swapinfo, 1, 0) == 0) {
- pagesize = getpagesize();
- *total = swapinfo.ksw_total * pagesize;
- *used = swapinfo.ksw_used * pagesize;
+ if((fp = fopen("/proc/meminfo","r"))) {
+ while(fgets(buf, 100, fp) && buf[0] != 'S');
+ if(sscanf(buf + 6, "%ld %ld", total, used) == 2)
if(*total != 0)
percent = (double)*used / (double)*total;
- }
- kvm_close(kd);
+ fclose(fp);
}
return percent;
}
+
#endif