[git commit] rdate: code shrink

Denys Vlasenko vda.linux at googlemail.com
Mon Jun 11 00:06:11 UTC 2012


commit: http://git.busybox.net/busybox/commit/?id=93c32f2dd2b9d7c06bc46be8adac704c08929da8
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 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 at 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(&current_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;


More information about the busybox-cvs mailing list