From 5a9cc1b0d20efa65d10adaaf06d0ef0aa089663c Mon Sep 17 00:00:00 2001 From: norly Date: Fri, 18 Nov 2011 00:05:15 +0100 Subject: Ye Olde Brick, hacked one very late night in 2010. Full of inefficient or maybe broken code, as well as the occasional memory leak. I am not proud of it and I was *really* tired back then. While this was an experiment in writing (f)ugly code and I just wanted something running, I have to admit that this code has served me well ever since. Too well to be bothered to ever look at it again, really... --- statuses/uptime.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 statuses/uptime.c (limited to 'statuses/uptime.c') diff --git a/statuses/uptime.c b/statuses/uptime.c new file mode 100644 index 0000000..8db1c45 --- /dev/null +++ b/statuses/uptime.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include "uptime.h" + +void status_uptime() +{ + char stline[16]; + int stfile; + size_t stlen; + int i; + int upts, uptm, upth, uptd; + + stfile = open("/proc/uptime", 0); + if (stfile != -1) + { + stlen = read(stfile, stline, sizeof(stline)); + close(stfile); + + for(i = 0; i < stlen; i++) + if (stline[i] == ' ') + stline[i] = '\0'; + + 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); + + fputs(" ^fg(#AAAAAA)up: ", stdout); + + if (uptd > 0) + printf("%dd ", uptd); + + printf("%d:%.2d" + + #ifdef SHOW_SECONDS + ":%.2d" + #endif + + " " + ,upth + ,uptm + + #ifdef SHOW_SECONDS + ,upts + #endif + ); + } +} -- cgit v1.2.3