From: Armaan Bhojwani Date: Sun, 11 Apr 2021 00:55:28 +0000 (-0400) Subject: tides: add current time info X-Git-Tag: v0.0.1~1 X-Git-Url: https://git.armaanb.net/?p=bin.git;a=commitdiff_plain;h=1a43f540183b46620023146663f8f82bd5d0680b tides: add current time info --- diff --git a/tides.c b/tides.c index d1eba77..18c430f 100644 --- a/tides.c +++ b/tides.c @@ -1,8 +1,8 @@ // Yet another (tm) fetch program #include -#include -#include +#include +#include #include #include @@ -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);