Mercurial > hg > toybox
comparison toys/posix/who.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 <rob@landley.net> |
---|---|
date | Tue, 13 Nov 2012 17:14:08 -0600 |
parents | 6df4ccc0acbe |
children | 53f165466f3b |
comparison
equal
deleted
inserted
replaced
693:4a5a250e0633 | 694:786841fdb1e0 |
---|---|
1 /* vi: set sw=4 ts=4: | 1 /* who.c - display who is on the system |
2 * | |
3 * who.c - display who is on the system | |
4 * | 2 * |
5 * Copyright 2012 ProFUSION Embedded Systems | 3 * Copyright 2012 ProFUSION Embedded Systems |
6 * | 4 * |
7 * by Luis Felipe Strano Moraes <lfelipe@profusion.mobi> | 5 * by Luis Felipe Strano Moraes <lfelipe@profusion.mobi> |
8 * | 6 * |
9 * See http://opengroup.org/onlinepubs/9699919799/utilities/who.html | 7 * See http://opengroup.org/onlinepubs/9699919799/utilities/who.html |
10 | 8 |
11 USE_WHO(NEWTOY(who, NULL, TOYFLAG_BIN)) | 9 USE_WHO(NEWTOY(who, NULL, TOYFLAG_BIN)) |
12 | 10 |
13 config WHO | 11 config WHO |
14 bool "who" | 12 bool "who" |
15 default n | 13 default n |
16 help | 14 help |
17 usage: who | 15 usage: who |
18 | 16 |
19 Print logged user information on system | 17 Print logged user information on system |
20 | |
21 */ | 18 */ |
22 | 19 |
23 #include "toys.h" | 20 #include "toys.h" |
24 | 21 |
25 void who_main(void) | 22 void who_main(void) |
26 { | 23 { |
27 struct utmpx *entry; | 24 struct utmpx *entry; |
28 | 25 |
29 setutxent(); | 26 setutxent(); |
30 | 27 |
31 while ((entry = getutxent())) { | 28 while ((entry = getutxent())) { |
32 if (entry->ut_type == USER_PROCESS) { | 29 if (entry->ut_type == USER_PROCESS) { |
33 time_t time; | 30 time_t time; |
34 int time_size; | 31 int time_size; |
35 char * times; | 32 char * times; |
36 | 33 |
37 time = entry->ut_tv.tv_sec; | 34 time = entry->ut_tv.tv_sec; |
38 times = ctime(&time); | 35 times = ctime(&time); |
39 time_size = strlen(times) - 2; | 36 time_size = strlen(times) - 2; |
40 printf("%s\t%s\t%*.*s\t(%s)\n", entry->ut_user, entry->ut_line, time_size, time_size, ctime(&time), entry->ut_host); | 37 printf("%s\t%s\t%*.*s\t(%s)\n", entry->ut_user, entry->ut_line, |
38 time_size, time_size, ctime(&time), entry->ut_host); | |
39 } | |
40 } | |
41 | 41 |
42 } | 42 endutxent(); |
43 } | |
44 | |
45 endutxent(); | |
46 } | 43 } |