diff options
author | Denys Vlasenko | 2012-06-11 02:06:11 +0200 |
---|---|---|
committer | Denys Vlasenko | 2012-06-11 02:06:11 +0200 |
commit | 93c32f2dd2b9d7c06bc46be8adac704c08929da8 (patch) | |
tree | a05060b2ac7f70d1069bb4d84ac1b9b3eb3c8b26 | |
parent | 605f2641d83f4294147bede9403a590a29a6674a (diff) | |
download | busybox-93c32f2dd2b9d7c06bc46be8adac704c08929da8.zip busybox-93c32f2dd2b9d7c06bc46be8adac704c08929da8.tar.gz |
rdate: code shrink
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/rdate.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/util-linux/rdate.c b/util-linux/rdate.c index 1f36d8f..2ca585f 100644 --- a/util-linux/rdate.c +++ b/util-linux/rdate.c @@ -1,7 +1,7 @@ /* vi: set sw=4 ts=4: */ /* * The Rdate command will ask a time server for the RFC 868 time - * and optionally set the system time. + * and optionally set the system time. * * by Sterling Huxley <sterling@europa.com> * @@ -11,9 +11,9 @@ //usage:#define rdate_trivial_usage //usage: "[-sp] HOST" //usage:#define rdate_full_usage "\n\n" -//usage: "Get and possibly set the system date and time from a remote HOST\n" -//usage: "\n -s Set the system date and time (default)" -//usage: "\n -p Print the date and time" +//usage: "Get and possibly set the system date/time from a remote HOST\n" +//usage: "\n -s Set the system date/time (default)" +//usage: "\n -p Print the date/time" #include "libbb.h" @@ -35,15 +35,16 @@ static time_t askremotedate(const char *host) fd = create_and_connect_stream_or_die(host, bb_lookup_port("time", "tcp", 37)); - if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */ + if (safe_read(fd, &nett, 4) != 4) /* read time from server */ bb_error_msg_and_die("%s did not send the complete time", host); - close(fd); + if (ENABLE_FEATURE_CLEAN_UP) + close(fd); - /* convert from network byte order to local byte order. + /* Convert from network byte order to local byte order. * RFC 868 time is the number of seconds * since 00:00 (midnight) 1 January 1900 GMT * the RFC 868 time 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT - * Subtract the RFC 868 time to get Linux epoch + * Subtract the RFC 868 time to get Linux epoch. */ return ntohl(nett) - RFC_868_BIAS; @@ -53,14 +54,14 @@ int rdate_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int rdate_main(int argc UNUSED_PARAM, char **argv) { time_t remote_time; - unsigned long flags; + unsigned flags; opt_complementary = "-1"; flags = getopt32(argv, "sp"); remote_time = askremotedate(argv[optind]); - if ((flags & 2) == 0) { + if (!(flags & 2)) { time_t current_time; time(¤t_time); @@ -71,7 +72,7 @@ int rdate_main(int argc UNUSED_PARAM, char **argv) bb_perror_msg_and_die("can't set time of day"); } - if ((flags & 1) == 0) + if ((flags & 2) || !(flags & 1)) printf("%s", ctime(&remote_time)); return EXIT_SUCCESS; |