Xinqi Bao's Git
projects
/
slstatus.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
Get rid of err.h as it is not portable
[slstatus.git]
/
components
/
swap.c
diff --git
a/components/swap.c
b/components/swap.c
index
e4eec64
..
b82ff46
100644
(file)
--- a/
components/swap.c
+++ b/
components/swap.c
@@
-1,5
+1,5
@@
/* See LICENSE file for copyright and license details. */
/* See LICENSE file for copyright and license details. */
-#i
nclude <err.h>
+#i
f defined(__linux__)
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
@@
-15,12
+15,12
@@
swap_free(void)
fp = fopen("/proc/meminfo", "r");
if (fp == NULL) {
fp = fopen("/proc/meminfo", "r");
if (fp == NULL) {
-
warn(
"Failed to open file /proc/meminfo");
+
fprintf(stderr,
"Failed to open file /proc/meminfo");
return NULL;
}
if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
return NULL;
}
if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
-
warn(
"swap_free: read error");
+
fprintf(stderr,
"swap_free: read error");
fclose(fp);
return NULL;
}
fclose(fp);
return NULL;
}
@@
-47,12
+47,12
@@
swap_perc(void)
fp = fopen("/proc/meminfo", "r");
if (fp == NULL) {
fp = fopen("/proc/meminfo", "r");
if (fp == NULL) {
-
warn(
"Failed to open file /proc/meminfo");
+
fprintf(stderr,
"Failed to open file /proc/meminfo");
return NULL;
}
if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
return NULL;
}
if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
-
warn(
"swap_perc: read error");
+
fprintf(stderr,
"swap_perc: read error");
fclose(fp);
return NULL;
}
fclose(fp);
return NULL;
}
@@
-83,11
+83,11
@@
swap_total(void)
fp = fopen("/proc/meminfo", "r");
if (fp == NULL) {
fp = fopen("/proc/meminfo", "r");
if (fp == NULL) {
-
warn(
"Failed to open file /proc/meminfo");
+
fprintf(stderr,
"Failed to open file /proc/meminfo");
return NULL;
}
if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
return NULL;
}
if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
-
warn(
"swap_total: read error");
+
fprintf(stderr,
"swap_total: read error");
fclose(fp);
return NULL;
}
fclose(fp);
return NULL;
}
@@
-110,11
+110,11
@@
swap_used(void)
fp = fopen("/proc/meminfo", "r");
if (fp == NULL) {
fp = fopen("/proc/meminfo", "r");
if (fp == NULL) {
-
warn(
"Failed to open file /proc/meminfo");
+
fprintf(stderr,
"Failed to open file /proc/meminfo");
return NULL;
}
if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
return NULL;
}
if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
-
warn(
"swap_used: read error");
+
fprintf(stderr,
"swap_used: read error");
fclose(fp);
return NULL;
}
fclose(fp);
return NULL;
}
@@
-134,3
+134,4
@@
swap_used(void)
return bprintf("%f", (float)(total - free - cached) / 1024 / 1024);
}
return bprintf("%f", (float)(total - free - cached) / 1024 / 1024);
}
+#endif