diff options
Diffstat (limited to 'dutmp.c')
-rw-r--r-- | dutmp.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -13,34 +13,35 @@ | |||
13 | 13 | ||
14 | #include "internal.h" | 14 | #include "internal.h" |
15 | #include <stdio.h> | 15 | #include <stdio.h> |
16 | #include <errno.h> | ||
16 | #include <utmp.h> | 17 | #include <utmp.h> |
18 | #define BB_DECLARE_EXTERN | ||
19 | #define bb_need_io_error | ||
20 | #include "messages.c" | ||
17 | 21 | ||
18 | static const char dutmp_usage[] = "dutmp\n" | 22 | static const char dutmp_usage[] = "dutmp\n" |
19 | "\n" | 23 | "\n" |
20 | |||
21 | "\tDump file or stdin utmp file format to stdout, pipe delimited.\n" | 24 | "\tDump file or stdin utmp file format to stdout, pipe delimited.\n" |
22 | "\tdutmp /var/run/utmp\n"; | 25 | "\tdutmp /var/run/utmp\n"; |
23 | 26 | ||
24 | extern int dutmp_main(int argc, char **argv) | 27 | extern int dutmp_main(int argc, char **argv) |
25 | { | 28 | { |
26 | 29 | ||
27 | FILE *f = stdin; | 30 | FILE *f; |
28 | struct utmp ut; | 31 | struct utmp ut; |
29 | 32 | ||
30 | if ((argc < 2) || (**(argv + 1) == '-')) { | 33 | if (argc<2) { |
34 | f = stdin; | ||
35 | } else if (*argv[1] == '-' ) { | ||
31 | usage(dutmp_usage); | 36 | usage(dutmp_usage); |
32 | } | 37 | } else { |
33 | 38 | f = fopen(argv[1], "r"); | |
34 | if (**(++argv) == 0) { | 39 | if (f == NULL) { |
35 | f = fopen(*(++argv), "r"); | 40 | fatalError(io_error, argv[1], strerror(errno)); |
36 | if (f < 0) { | ||
37 | perror(*argv); | ||
38 | exit(FALSE); | ||
39 | } | 41 | } |
40 | } | 42 | } |
41 | 43 | ||
42 | while (fread(&ut, 1, sizeof(struct utmp), f)) { | 44 | while (fread(&ut, sizeof(struct utmp), 1, f)) { |
43 | // printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n", | ||
44 | printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", | 45 | printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", |
45 | ut.ut_type, ut.ut_pid, ut.ut_line, | 46 | ut.ut_type, ut.ut_pid, ut.ut_line, |
46 | ut.ut_id, ut.ut_user, ut.ut_host, | 47 | ut.ut_id, ut.ut_user, ut.ut_host, |