• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* w.c - shows logged in users
2  *
3  * Copyright 2012 Gaurang Shastri <gmshastri@gmail.com>
4 
5 USE_W(NEWTOY(w, NULL, TOYFLAG_USR|TOYFLAG_BIN))
6 
7 config W
8   bool "w"
9   default y
10   depends on TOYBOX_UTMPX
11   help
12     usage: w
13 
14     Show who is logged on and since how long they logged in.
15 */
16 
17 #include "toys.h"
18 
w_main(void)19 void w_main(void)
20 {
21   struct utmpx *x;
22 
23   xprintf("USER     TTY             LOGIN@              FROM");
24   setutxent();
25   while ((x=getutxent()) != NULL) {
26     if (x->ut_type==7) {
27       time_t tt = x->ut_tv.tv_sec;
28 
29       xprintf("\n%-9.8s%-9.8s %-4.24s (%-1.12s)", x->ut_user, x->ut_line,
30         ctime(&tt), x->ut_host);
31     }
32   }
33   xputc('\n');
34 }
35