view toys/other/w.c @ 694:786841fdb1e0

Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style. The actual code should be the same afterward, this is just cosmetic refactoring.
author Rob Landley <>
date Tue, 13 Nov 2012 17:14:08 -0600
parents 6df4ccc0acbe
children 685a0da6ca59
line wrap: on
line source

/* w.c - shows logged in users
 * Copyright 2012 Gaurang Shastri <>


config W
  bool "w"
  default y
    usage: w

    Show who is logged on and since how long they logged in.

#include "toys.h"

void w_main(void)
  struct utmpx *x;

  xprintf("USER     TTY             LOGIN@              FROM");
  while ((x=getutxent()) != NULL) {
    if (x->ut_type==7) {
      time_t tt = x->ut_tv.tv_sec;

      xprintf("\n%-9.8s%-9.8s %-4.24s (%-1.12s)", x->ut_user, x->ut_line,
        ctime(&tt), x->ut_host);