From ccae0b18fc908f6956626ca26ba19663140ebaa3 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Mon, 30 Jan 2017 16:27:22 +0100 Subject: rsmemsiz: Use sysinfo to obtain uptime. Now that uptime() is only used to obtain the load average it's trivial to replace. Signed-off-by: Ralf Baechle --- rose/rsmemsiz.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'rose') diff --git a/rose/rsmemsiz.c b/rose/rsmemsiz.c index 1d409ae..b2ad0da 100644 --- a/rose/rsmemsiz.c +++ b/rose/rsmemsiz.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -50,17 +51,16 @@ static char buf[300]; #define SET_IF_DESIRED(x,y) if (x) *(x) = (y) /* evals 'x' twice */ -static int uptime(double *uptime_secs) +static int getuptime(double *uptime_secs) { - double up=0; + struct sysinfo si; + + if (sysinfo(&si) < 0) + return -1; + + *uptime_secs = si.uptime; - FILE_TO_BUF(PROC_UPTIME_FILE) - if (sscanf(buf, "%lf %*f", &up) < 1) { - fprintf(stdout, "ERROR: Bad data in %s\r", PROC_UPTIME_FILE); return 0; - } - SET_IF_DESIRED(uptime_secs, up); - return up; /* assume never be zero seconds in practice */ } /* The following /proc/meminfo parsing routine assumes the following format: @@ -140,7 +140,7 @@ int main(int argc, char **argv) } /* read and calculate the amount of uptime and format it nicely */ - uptime(&uptime_secs); + getuptime(&uptime_secs); updays = (int) uptime_secs / (60*60*24); upminutes = (int) uptime_secs / 60; uphours = upminutes / 60; -- cgit v1.2.3