Fix some compiler warnings emitted by gcc-4.8.0
[oweals/busybox.git] / util-linux / hwclock.c
index ee68be8c5aea7ad6360b9bb957f930ae59133b2e..379eeb25375db4dfc3f469db68864e4e9f8ad56f 100644 (file)
@@ -43,7 +43,7 @@ static time_t read_rtc(const char **pp_rtcname, struct timeval *sys_tv, int utc)
                while (1) {
                        rtc_read_tm(&tm_time, fd);
                        gettimeofday(sys_tv, NULL);
-                       if (before != tm_time.tm_sec)
+                       if (before != (int)tm_time.tm_sec)
                                break;
                }
        }
@@ -60,25 +60,31 @@ static void show_clock(const char **pp_rtcname, int utc)
 #if SHOW_HWCLOCK_DIFF
        struct timeval sys_tv;
 #endif
-       time_t t;
-       char *cp;
+       time_t t = read_rtc(pp_rtcname, &sys_tv, utc);
 
-       t = read_rtc(pp_rtcname, &sys_tv, utc);
-       cp = ctime(&t);
+#if ENABLE_LOCALE_SUPPORT
+       /* Standard hwclock uses locale-specific output format */
+       char cp[64];
+       struct tm *ptm = localtime(&t);
+       strftime(cp, sizeof(cp), "%c", ptm);
+#else
+       char *cp = ctime(&t);
        strchrnul(cp, '\n')[0] = '\0';
+#endif
+
 #if !SHOW_HWCLOCK_DIFF
        printf("%s  0.000000 seconds\n", cp);
 #else
        {
                long diff = sys_tv.tv_sec - t;
                if (diff < 0 /*&& tv.tv_usec != 0*/) {
-                       /* Why? */
-                       /* diff >= 0 is ok:   diff < 0, can't just use tv.tv_usec: */
-                       /*   45.520820          43.520820 */
-                       /* - 44.000000        - 45.000000 */
-                       /* =  1.520820        = -1.479180, not -2.520820! */
+                       /* Why we need diff++? */
+                       /* diff >= 0 is ok: | diff < 0, can't just use tv.tv_usec: */
+                       /*   45.520820      |   43.520820 */
+                       /* - 44.000000      | - 45.000000 */
+                       /* =  1.520820      | = -1.479180, not -2.520820! */
                        diff++;
-                       /* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
+                       /* Should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
                        sys_tv.tv_usec = 999999 - sys_tv.tv_usec;
                }
                printf("%s  %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec);
@@ -268,8 +274,8 @@ static void set_system_clock_timezone(int utc)
 //usage:     "\n       -w      Set hardware clock from system time"
 //usage:     "\n       -t      Set in-kernel timezone, correct system time"
 //usage:     "\n               if hardware clock is in local time"
-//usage:     "\n       -u      Hardware clock is in UTC"
-//usage:     "\n       -l      Hardware clock is in local time"
+//usage:     "\n       -u      Assume hardware clock is kept in UTC"
+//usage:     "\n       -l      Assume hardware clock is kept in local time"
 //usage:     "\n       -f FILE Use specified device (e.g. /dev/rtc2)"
 
 #define HWCLOCK_OPT_LOCALTIME   0x01