summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-05-15 17:14:24 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-05-15 17:14:24 +0800
commit4968f459b5a47b723b550d9d50a4d17f5031f3e9 (patch)
treed8398b6250acb8dfa894ab2cb58ecbf62b0a129e
parentbd1709e7222362c7b7fae0950326d21748216d62 (diff)
downloadpttbbs-4968f459b5a47b723b550d9d50a4d17f5031f3e9.tar
pttbbs-4968f459b5a47b723b550d9d50a4d17f5031f3e9.tar.gz
pttbbs-4968f459b5a47b723b550d9d50a4d17f5031f3e9.tar.bz2
pttbbs-4968f459b5a47b723b550d9d50a4d17f5031f3e9.tar.lz
pttbbs-4968f459b5a47b723b550d9d50a4d17f5031f3e9.tar.xz
pttbbs-4968f459b5a47b723b550d9d50a4d17f5031f3e9.tar.zst
pttbbs-4968f459b5a47b723b550d9d50a4d17f5031f3e9.zip
*** empty log message ***
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@174 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-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