annotate toys/other/w.c @ 684:4d9fa8b8a300

Use stridx.
author Rob Landley <rob@landley.net>
date Fri, 02 Nov 2012 09:50:09 -0500
parents 6df4ccc0acbe
children 786841fdb1e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
630
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * w.c - shows logged in users
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright 2012 Gaurang Shastri <gmshastri@gmail.com>
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
6
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 USE_W(NEWTOY(w, NULL, TOYFLAG_USR|TOYFLAG_BIN))
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 config W
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
10 bool "w"
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 default y
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 help
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 usage: w
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
14
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 Show who is logged on and since how long they logged in.
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
16 */
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
17
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 #include "toys.h"
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 void w_main(void)
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 {
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 struct utmpx *x;
631
7c1a825f5afb Cleanup of w command.
Rob Landley <rob@landley.net>
parents: 630
diff changeset
23
630
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 xprintf("USER TTY LOGIN@ FROM");
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 setutxent();
631
7c1a825f5afb Cleanup of w command.
Rob Landley <rob@landley.net>
parents: 630
diff changeset
26 while ((x=getutxent()) != NULL)
7c1a825f5afb Cleanup of w command.
Rob Landley <rob@landley.net>
parents: 630
diff changeset
27 if (x->ut_type==7) {
7c1a825f5afb Cleanup of w command.
Rob Landley <rob@landley.net>
parents: 630
diff changeset
28 time_t tt = x->ut_tv.tv_sec;
630
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
29
631
7c1a825f5afb Cleanup of w command.
Rob Landley <rob@landley.net>
parents: 630
diff changeset
30 xprintf("\n%-9.8s%-9.8s %-4.24s (%-1.12s)", x->ut_user, x->ut_line,
7c1a825f5afb Cleanup of w command.
Rob Landley <rob@landley.net>
parents: 630
diff changeset
31 ctime(&tt), x->ut_host);
630
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 }
631
7c1a825f5afb Cleanup of w command.
Rob Landley <rob@landley.net>
parents: 630
diff changeset
33 xputc('\n');
630
03f18afb4b44 Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 }