]> git.armaanb.net Git - bin.git/commitdiff
tides: add current time info
authorArmaan Bhojwani <me@armaanb.net>
Sun, 11 Apr 2021 00:55:28 +0000 (20:55 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Sun, 11 Apr 2021 00:56:38 +0000 (20:56 -0400)
tides.c

diff --git a/tides.c b/tides.c
index d1eba77eb19ad3f0eddf7764a4d5d1552d28e435..18c430f8220e3cc1e087253f6d05a5905dd4bdc7 100644 (file)
--- a/tides.c
+++ b/tides.c
@@ -1,8 +1,8 @@
 // Yet another (tm) fetch program
 
 #include <unistd.h>
-#include <sys/utsname.h> 
-#include <sys/sysinfo.h> 
+#include <sys/utsname.h>
+#include <sys/sysinfo.h>
 #include <time.h>
 
 #include <limits.h>
@@ -20,14 +20,22 @@ main(void)
        char username[LOGIN_NAME_MAX];
        getlogin_r(username, LOGIN_NAME_MAX);
 
-       // Get kernel info
-       struct utsname kernel;
-       uname(&kernel);
-
        // Get assorted system info
        struct sysinfo info;
        sysinfo(&info);
 
+       // Get uptime
+       struct tm *uptime = gmtime(&info.uptime);
+
+       // Get current time
+       time_t rawtime;
+       time(&rawtime);
+       struct tm *wtime = localtime(&rawtime);
+
+       // Get kernel info
+       struct utsname kernel;
+       uname(&kernel);
+
        /* Get memory info from /proc. Inspired by busybox free.c, which is
                 GPLv2 licensed */
        char buf[60]; // actual lines we expect are ~30 chars or less
@@ -48,8 +56,10 @@ main(void)
 
        // Display
        printf("%s@%s\n", username, hostname);
+       printf("%d-%02d-%02d %02d:%02d:%02d\n", wtime->tm_year + 1900, wtime->tm_mon,
+                                wtime->tm_mday, wtime->tm_hour, wtime->tm_min, wtime->tm_sec);
+       printf("%0.0f/%0.0f MB RAM\n", (total_kb - avail_kb)/1024.0, total_kb/1024.0);
        printf("%s %s\n", kernel.sysname, kernel.release);
-       struct tm *uptime = gmtime(&info.uptime);
        printf("Up %02dh %02dm %02ds\n", uptime->tm_hour, uptime->tm_min,
                                 uptime->tm_sec);
        printf("%0.0f/%0.0f MB RAM\n", (total_kb - avail_kb)/1024.0, total_kb/1024.0);