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