From b67a8ceaf110fe0bdad6c8da78568662cc50e5bb Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 18 Jul 2012 20:21:50 -0500 Subject: Add w command by Gaurang Shastri. --- toys/w.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 toys/w.c (limited to 'toys/w.c') diff --git a/toys/w.c b/toys/w.c new file mode 100644 index 00000000..7e5a2964 --- /dev/null +++ b/toys/w.c @@ -0,0 +1,47 @@ +/* vi: set sw=4 ts=4: + * + * w.c - shows logged in users + * + * Copyright 2012 Gaurang Shastri + * + * Not in SUSv4. + +USE_W(NEWTOY(w, NULL, TOYFLAG_USR|TOYFLAG_BIN)) + +config W + bool "w" + default y + help + usage: w + + Show who is logged on and since how long they logged in. + +*/ + +#include "toys.h" + +void w_main(void) +{ + struct utmpx *x; + time_t time_val; + xprintf("USER TTY LOGIN@ FROM"); + setutxent(); + x=getutxent(); + while(x!=NULL) { + if(x->ut_type==7) { + xprintf("\n"); + xprintf("%-9.8s",x->ut_user); + xprintf("%-9.8s",x->ut_line); + + xprintf(" "); + time_val = (x->ut_tv.tv_sec); + xprintf("%-4.24s",ctime(&time_val)); + + xprintf(" ("); + xprintf("%-1.12s",x->ut_host); + xprintf(")"); + } + x=getutxent(); + } + xprintf("\n"); +} -- cgit v1.2.3