Xinqi Bao's Git
projects
/
slstatus.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
Format error messages properly
[slstatus.git]
/
components
/
swap.c
diff --git
a/components/swap.c
b/components/swap.c
index
0aad074
..
f3bbeb2
100644
(file)
--- a/
components/swap.c
+++ b/
components/swap.c
@@
-1,6
+1,6
@@
/* See LICENSE file for copyright and license details. */
#if defined(__linux__)
/* See LICENSE file for copyright and license details. */
#if defined(__linux__)
-#include <err.h>
+#include <err
no
.h>
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
@@
-16,12
+16,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, "fopen '/proc/meminfo': %s\n", strerror(errno)
);
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, "fread '/proc/meminfo': %s\n", strerror(errno)
);
fclose(fp);
return NULL;
}
fclose(fp);
return NULL;
}
@@
-48,12
+48,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, "fopen '/proc/meminfo': %s\n", strerror(errno)
);
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, "fread '/proc/meminfo': %s\n", strerror(errno)
);
fclose(fp);
return NULL;
}
fclose(fp);
return NULL;
}
@@
-84,11
+84,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, "fopen '/proc/meminfo': %s\n", strerror(errno)
);
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, "fread '/proc/meminfo': %s\n", strerror(errno)
);
fclose(fp);
return NULL;
}
fclose(fp);
return NULL;
}
@@
-111,11
+111,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, "fopen '/proc/meminfo': %s\n", strerror(errno)
);
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, "fread '/proc/meminfo': %s\n", strerror(errno)
);
fclose(fp);
return NULL;
}
fclose(fp);
return NULL;
}