Hi All,
Please find attached the initial implementation of "w" command.
Output after compiling my code with toybox :
{{{
[root@stark toybox-0.3.0]# ./toybox w
USER TTY LOGIN@ FROM
root tty2 Wed Jul 11 18:29:24 2012 ( )
rpmuser pts/1 Wed Jul 11 21:33:15 2012 (43.88.80.109)
rpmuser pts/2 Wed Jul 11 19:23:09 2012 (:0.0)
rpmuser pts/3 Tue Jul 17 20:33:41 2012 (43.88.80.208)
}}}
Dear Rob, let me know your comments if any.
Thanks & Regards,
Gaurang Shastri
/* vi: set sw=4 ts=4:
*
* w.c - shows logged in users
*
* Copyright 2012 Gaurang Shastri <[email protected]>
*
* 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");
}
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net