diff options
author | Denis Vlasenko | 2006-11-18 22:03:26 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-11-18 22:03:26 +0000 |
commit | 61126ab30a90b74e45a79ccb97074ab71afa6054 (patch) | |
tree | cbc4d021bafef2561cbb37ea0d0c955bfd985401 /networking/udhcp/dumpleases.c | |
parent | 5a3395bc01cd4b11309595a6ecdaf32f8279f378 (diff) | |
download | busybox-61126ab30a90b74e45a79ccb97074ab71afa6054.zip busybox-61126ab30a90b74e45a79ccb97074ab71afa6054.tar.gz |
small fixes: using fd-based io instead of FILE*-based,
missed O_TRUNC, etc
Diffstat (limited to 'networking/udhcp/dumpleases.c')
-rw-r--r-- | networking/udhcp/dumpleases.c | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c index 4422d30..a0e81bb 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c @@ -13,9 +13,9 @@ int dumpleases_main(int argc, char *argv[]) { - FILE *fp; + int fp; int i, c, mode = REMAINING; - long expires; + unsigned long expires; const char *file = LEASES_FILE; struct dhcpOfferedAddr lease; struct in_addr addr; @@ -43,11 +43,11 @@ int dumpleases_main(int argc, char *argv[]) } } - fp = xfopen(file, "r"); + fp = xopen(file, O_RDONLY); printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at"); /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ - while (fread(&lease, sizeof(lease), 1, fp)) { + while (full_read(fp, &lease, sizeof(lease)) == sizeof(lease)) { printf(":%02x"+1, lease.chaddr[0]); for (i = 1; i < 6; i++) { printf(":%02x", lease.chaddr[i]); @@ -59,23 +59,16 @@ int dumpleases_main(int argc, char *argv[]) if (!expires) printf("expired\n"); else { - if (expires > 60*60*24) { - printf("%ld days, ", expires / (60*60*24)); - expires %= 60*60*24; - } - if (expires > 60*60) { - printf("%ld hours, ", expires / (60*60)); - expires %= 60*60; - } - if (expires > 60) { - printf("%ld minutes, ", expires / 60); - expires %= 60; - } - printf("%ld seconds\n", expires); + unsigned d, h, m; + d = expires / (24*60*60); expires %= (24*60*60); + h = expires / (60*60); expires %= (60*60); + m = expires / 60; expires %= 60; + if (d) printf("%u days ", d); + printf("%02u:%02u:%02u\n", h, m, (unsigned)expires); } - } else printf("%s", ctime(&expires)); + } else fputs(ctime(&expires), stdout); } - fclose(fp); + /* close(fp); */ return 0; } |