summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2024-03-10 16:50:28 +0100
committercgzones <cgzones@googlemail.com>2024-03-27 20:06:42 +0100
commit4806b4ebfb045c9162b8a2a0213f7b9bc87e1710 (patch)
treeec5c3ef18b0634c2a88377f2e8c95b33a39edef8
parent3eb8bfa4cc1712621a18aaf12bef6420a19e55c0 (diff)
Avoid glibc FILE API for uptime reading
-rw-r--r--linux/Platform.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/linux/Platform.c b/linux/Platform.c
index 7708a573..e3f6fa60 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -258,15 +258,21 @@ const MeterClass* const Platform_meterTypes[] = {
};
int Platform_getUptime(void) {
+ char uptimedata[64] = {0};
+
+ ssize_t uptimeread = xReadfile(PROCDIR "/uptime", uptimedata, sizeof(uptimedata));
+ if (uptimeread < 1) {
+ return 0;
+ }
+
double uptime = 0;
- FILE* fd = fopen(PROCDIR "/uptime", "r");
- if (fd) {
- int n = fscanf(fd, "%64lf", &uptime);
- fclose(fd);
- if (n != 1) {
- return 0;
- }
+ double idle = 0;
+
+ int n = sscanf(uptimedata, "%lf %lf", &uptime, &idle);
+ if (n != 2) {
+ return 0;
}
+
return floor(uptime);
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy