From 1a43f540183b46620023146663f8f82bd5d0680b Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Sat, 10 Apr 2021 20:55:28 -0400 Subject: [PATCH] tides: add current time info --- tides.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) 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); -- 2.39.2