X-Git-Url: https://git.enpas.org/?p=sysstatus.git;a=blobdiff_plain;f=statuses%2Fuptime.c;h=fba6a6f0b90523ae8f971c1e46b56a5498b036eb;hp=d512cdb84512f143a5fc2a3e0a4d91385e5e54c4;hb=2ddbfa53a31360e50565345a1ac08c0799c8243e;hpb=9102c7c65421f2ef3e415c7e76a741657e34663b diff --git a/statuses/uptime.c b/statuses/uptime.c index d512cdb..fba6a6f 100644 --- a/statuses/uptime.c +++ b/statuses/uptime.c @@ -7,55 +7,52 @@ void status_uptime() { - char stline[16]; - int stfile; - ssize_t stlen; - int i; - int upts, uptm, upth, uptd; - - fputs(" ^fg(#AAAAAA)up: ", stdout); - - stlen = fileRead(stline, sizeof(stline), "/proc/uptime"); - if (stlen < 0) - { - fputs(" ^fg(red)ERROR ", stdout); - return; - } - - // Cut first element - for(i = 0; i < stlen; i++) - { - if (stline[i] == ' ') - { - stline[i] = '\0'; - break; - } - } - - // Split time into days, hours, mins, secs - upts = atoi(stline); - uptd = upts / (24 * 60 * 60); - upts -= uptd * (24 * 60 * 60); - upth = upts / (60 * 60); - upts -= upth * (60 * 60); - uptm = upts / (60); - upts -= uptm * (60); - - if (uptd > 0) - printf("%dd ", uptd); - - printf("%d:%.2d" - - #ifdef SHOW_SECONDS - ":%.2d" - #endif - - " " - ,upth - ,uptm - - #ifdef SHOW_SECONDS - ,upts - #endif - ); + char stline[16]; + int stfile; + ssize_t stlen; + int i; + int upts, uptm, upth, uptd; + + fputs(" ^fg(#AAAAAA)up: ", stdout); + + stlen = fileRead(stline, sizeof(stline), "/proc/uptime"); + if (stlen < 0) { + fputs(" ^fg(red)ERROR ", stdout); + return; + } + + /* Cut first element */ + for(i = 0; i < stlen; i++) { + if (stline[i] == ' ') { + stline[i] = '\0'; + break; + } + } + + // Split time into days, hours, mins, secs + upts = atoi(stline); + uptd = upts / (24 * 60 * 60); + upts -= uptd * (24 * 60 * 60); + upth = upts / (60 * 60); + upts -= upth * (60 * 60); + uptm = upts / (60); + upts -= uptm * (60); + + if (uptd > 0) { + printf("%dd ", uptd); + } + + printf("%d:%.2d" + #ifdef SHOW_SECONDS + ":%.2d" + #endif + + " " + ,upth + ,uptm + + #ifdef SHOW_SECONDS + ,upts + #endif + ); }