commit d2174ff8515f933fff4818281fc55620ea71d6d2
parent 1ecd3b20211e20271bdc5d7e71104fd65416aa64
Author: sam-barr <samfbarr@outlook.com>
Date: Thu, 23 Apr 2020 10:43:44 -0500
Merge branch 'master' of https://github.com/sam-barr/paleofetch
Diffstat:
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
@@ -8,6 +8,14 @@ Example output:

+Dependencies
+------------
+
+Paleofetch requires `libX11` and `libpci`. If you're running Xorg you should already have
+the former. On Arch Linux, you should have `libpci` already installed if you have `pciutils`
+installed. On other linux distrobutions, you may need to install libpci seperatley
+if its not already present.
+
Compiling
---------
diff --git a/paleofetch.c b/paleofetch.c
@@ -185,19 +185,23 @@ char *get_host() {
char *get_uptime() {
long seconds = my_sysinfo.uptime;
- long hours = seconds / 3600;
- long minutes = (seconds / 60) % 60;
- seconds = seconds % 60;
+ struct { char *name; int secs; } units[] = {
+ { "day", 60 * 60 * 24 },
+ { "hour", 60 * 60 },
+ { "min", 60 },
+ };
+ int n, len = 0;
char *uptime = malloc(BUF_SIZE);
+ for (int i = 0; i < 3; ++i ) {
+ if ((n = seconds / units[i].secs))
+ len += snprintf(uptime + len, BUF_SIZE - len,
+ "%d %s%s, ", n, units[i].name, n > 1 ? "s": "");
+ seconds %= units[i].secs;
+ }
- if(hours > 0)
- snprintf(uptime, BUF_SIZE, "%ld hours, %ld mins", hours, minutes);
- else if(minutes > 0)
- snprintf(uptime, BUF_SIZE, "%ld mins", minutes);
- else
- snprintf(uptime, BUF_SIZE, "%ld secs", seconds);
-
+ // null-terminate at the trailing comma
+ uptime[len - 2] = '\0';
return uptime;
}