summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);
}