Mercurial > hg > toybox
changeset 631:7c1a825f5afb
Cleanup of w command.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 18 Jul 2012 20:28:19 -0500 |
parents | 03f18afb4b44 |
children | 6cafecf34728 |
files | toys/w.c |
diffstat | 1 files changed, 7 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/w.c Wed Jul 18 20:21:50 2012 -0500 +++ b/toys/w.c Wed Jul 18 20:28:19 2012 -0500 @@ -15,7 +15,6 @@ usage: w Show who is logged on and since how long they logged in. - */ #include "toys.h" @@ -23,25 +22,15 @@ 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); + while ((x=getutxent()) != NULL) + if (x->ut_type==7) { + time_t tt = x->ut_tv.tv_sec; - xprintf(" "); - time_val = (x->ut_tv.tv_sec); - xprintf("%-4.24s",ctime(&time_val)); - - xprintf(" ("); - xprintf("%-1.12s",x->ut_host); - xprintf(")"); + xprintf("\n%-9.8s%-9.8s %-4.24s (%-1.12s)", x->ut_user, x->ut_line, + ctime(&tt), x->ut_host); } - x=getutxent(); - } - xprintf("\n"); + xputc('\n'); }