From 4806b4ebfb045c9162b8a2a0213f7b9bc87e1710 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 10 Mar 2024 16:50:28 +0100 Subject: Avoid glibc FILE API for uptime reading --- linux/Platform.c | 20 +++++++++++++------- 1 file 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); } -- cgit v1.2.3