diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-05-16 20:07:38 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-05-16 20:07:38 +0000 |
commit | 499f65fb98a8258f8704b52efb3a99da0c82f785 (patch) | |
tree | 8bb86bf2d07ab298eff29daea039449e87d90166 /miscutils | |
parent | 969f9b0486792829378ff7397ee53c1475b22cdc (diff) | |
download | busybox-w32-499f65fb98a8258f8704b52efb3a99da0c82f785.tar.gz busybox-w32-499f65fb98a8258f8704b52efb3a99da0c82f785.tar.bz2 busybox-w32-499f65fb98a8258f8704b52efb3a99da0c82f785.zip |
Some updates for better portability.
-Erik
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/dutmp.c | 35 | ||||
-rw-r--r-- | miscutils/mt.c | 2 |
2 files changed, 17 insertions, 20 deletions
diff --git a/miscutils/dutmp.c b/miscutils/dutmp.c index fab1a7b99..f264fd75b 100644 --- a/miscutils/dutmp.c +++ b/miscutils/dutmp.c | |||
@@ -8,22 +8,20 @@ | |||
8 | * versions of 'who', 'last', etc. IP Addr is output in hex, | 8 | * versions of 'who', 'last', etc. IP Addr is output in hex, |
9 | * little endian on x86. | 9 | * little endian on x86. |
10 | * | 10 | * |
11 | * made against libc6 | 11 | * Modified to support all sort of libcs by |
12 | * Erik Andersen <andersen@lineo.com> | ||
12 | */ | 13 | */ |
13 | 14 | ||
14 | #include "internal.h" | 15 | #include "internal.h" |
15 | #include <stdio.h> | 16 | #include <sys/types.h> |
17 | #include <sys/stat.h> | ||
18 | #include <fcntl.h> | ||
19 | |||
16 | #include <errno.h> | 20 | #include <errno.h> |
17 | #define BB_DECLARE_EXTERN | 21 | #define BB_DECLARE_EXTERN |
18 | #define bb_need_io_error | 22 | #define bb_need_io_error |
19 | #include "messages.c" | 23 | #include "messages.c" |
20 | |||
21 | #if defined(__GLIBC__) | ||
22 | #include <utmp.h> | 24 | #include <utmp.h> |
23 | #else | ||
24 | #include <utmp-wrap.h> | ||
25 | #define utmp new_utmp | ||
26 | #endif | ||
27 | 25 | ||
28 | 26 | ||
29 | static const char dutmp_usage[] = "dutmp [FILE]\n" | 27 | static const char dutmp_usage[] = "dutmp [FILE]\n" |
@@ -36,27 +34,26 @@ static const char dutmp_usage[] = "dutmp [FILE]\n" | |||
36 | extern int dutmp_main(int argc, char **argv) | 34 | extern int dutmp_main(int argc, char **argv) |
37 | { | 35 | { |
38 | 36 | ||
39 | FILE *f; | 37 | int file; |
40 | struct utmp ut; | 38 | struct utmp ut; |
41 | 39 | ||
42 | if (argc<2) { | 40 | if (argc<2) { |
43 | f = stdin; | 41 | file = fileno(stdin); |
44 | } else if (*argv[1] == '-' ) { | 42 | } else if (*argv[1] == '-' ) { |
45 | usage(dutmp_usage); | 43 | usage(dutmp_usage); |
46 | } else { | 44 | } else { |
47 | f = fopen(argv[1], "r"); | 45 | file = open(argv[1], O_RDONLY); |
48 | if (f == NULL) { | 46 | if (file < 0) { |
49 | fatalError(io_error, argv[1], strerror(errno)); | 47 | fatalError(io_error, argv[1], strerror(errno)); |
50 | } | 48 | } |
51 | } | 49 | } |
52 | 50 | ||
53 | while (fread(&ut, sizeof(struct utmp), 1, f)) { | 51 | while (read(file, (void*)&ut, sizeof(struct utmp))) { |
54 | printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", | 52 | printf("%d|%d|%s|%s|%s|%s|%s|%lx\n", |
55 | ut.ut_type, ut.ut_pid, ut.ut_line, | 53 | ut.ut_type, ut.ut_pid, ut.ut_line, |
56 | ut.ut_id, ut.ut_user, ut.ut_host, | 54 | ut.ut_id, ut.ut_user, ut.ut_host, |
57 | ut.ut_exit.e_termination, ut.ut_exit.e_exit, | 55 | ctime(&(ut.ut_time)), |
58 | ut.ut_session, ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, | 56 | (long)ut.ut_addr); |
59 | ut.ut_addr_v6[0]); | ||
60 | } | 57 | } |
61 | 58 | ||
62 | exit(TRUE); | 59 | exit(TRUE); |
diff --git a/miscutils/mt.c b/miscutils/mt.c index 28922f8d9..44f23884c 100644 --- a/miscutils/mt.c +++ b/miscutils/mt.c | |||
@@ -61,7 +61,7 @@ extern int mt_main(int argc, char **argv) | |||
61 | struct mtop op; | 61 | struct mtop op; |
62 | int fd; | 62 | int fd; |
63 | 63 | ||
64 | if ((argc != 2 && argc != 3) || **(argv + 1) == '-') { | 64 | if ((argc != 2 && argc != 3) && **(argv + 1) != '-') { |
65 | usage(mt_usage); | 65 | usage(mt_usage); |
66 | } | 66 | } |
67 | 67 | ||