(I was looking at this code because I was looking at the output in a bug
report, and wasn't sure what `up  1:09` meant. It's annoying that -p is
a lot more readable, but doesn't include load averages, otherwise I'd be
tempted to move Android's bugreports over to `uptime -p` so that no-one
would ever have to scratch their heads about this again...)
---
 toys/other/uptime.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
From b5020ab9ae7ce94ec8c765db7978ae009aad9b48 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Tue, 21 Sep 2021 12:48:12 -0700
Subject: [PATCH] uptime: trivial modernization.

(I was looking at this code because I was looking at the output in a bug
report, and wasn't sure what `up  1:09` meant. It's annoying that -p is
a lot more readable, but doesn't include load averages, otherwise I'd be
tempted to move Android's bugreports over to `uptime -p` so that no-one
would ever have to scratch their heads about this again...)
---
 toys/other/uptime.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/toys/other/uptime.c b/toys/other/uptime.c
index 001af02c..c7adf473 100644
--- a/toys/other/uptime.c
+++ b/toys/other/uptime.c
@@ -28,7 +28,7 @@ void uptime_main(void)
   struct sysinfo info;
   time_t t;
   struct tm *tm;
-  unsigned int days, hours, minutes;
+  unsigned int weeks, days, hours, minutes;
   struct utmpx *entry;
   int users = 0;
 
@@ -37,7 +37,7 @@ void uptime_main(void)
   time(&t);
 
   // Just show the time of boot?
-  if (toys.optflags & FLAG_s) {
+  if (FLAG(s)) {
     t -= info.uptime;
     tm = localtime(&t);
     strftime(toybuf, sizeof(toybuf), "%F %T", tm);
@@ -54,10 +54,9 @@ void uptime_main(void)
   hours = info.uptime%24;
   days = info.uptime/24;
 
-  if (toys.optflags & FLAG_p) {
-    int weeks = days/7;
+  if (FLAG(p)) {
+    weeks = days/7;
     days %= 7;
-
     xprintf("up %d week%s, %d day%s, %d hour%s, %d minute%s\n",
         weeks, (weeks!=1)?"s":"",
         days, (days!=1)?"s":"",
-- 
2.33.0.464.g1972c5931b-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to