diff options
author | norly <ny-git@enpas.org> | 2011-11-18 00:05:15 +0100 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2011-11-18 00:05:15 +0100 |
commit | 5a9cc1b0d20efa65d10adaaf06d0ef0aa089663c (patch) | |
tree | f36927f31ffb22385c90b9cb43afd7c99da19344 /statuses/uptime.c |
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...
Diffstat (limited to 'statuses/uptime.c')
-rw-r--r-- | statuses/uptime.c | 53 |
1 files changed, 53 insertions, 0 deletions
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 <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> +#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 + ); + } +} |