aboutsummaryrefslogtreecommitdiff
path: root/util-linux/hwclock.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-07 10:36:41 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-07 10:36:41 +0100
commit0c58cc706fff6a2a954e92ea271ce2b400dee60e (patch)
tree039eda8e69ca03af96d87b6824fd269f35ecc60f /util-linux/hwclock.c
parent6959f6bc23abb9057c3ed4330dad1bc8f4a1dd7a (diff)
downloadbusybox-w32-0c58cc706fff6a2a954e92ea271ce2b400dee60e.tar.gz
busybox-w32-0c58cc706fff6a2a954e92ea271ce2b400dee60e.tar.bz2
busybox-w32-0c58cc706fff6a2a954e92ea271ce2b400dee60e.zip
hwclock: make commented-out code compilable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/hwclock.c')
-rw-r--r--util-linux/hwclock.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
index 7f4c563e6..a8b0bdf93 100644
--- a/util-linux/hwclock.c
+++ b/util-linux/hwclock.c
@@ -23,7 +23,12 @@
23 * "time between hwclock was started and we saw CMOS tick" quantity. 23 * "time between hwclock was started and we saw CMOS tick" quantity.
24 * It's useless since hwclock is started at a random moment, 24 * It's useless since hwclock is started at a random moment,
25 * thus the quantity is also random, useless. Showing 0.000000 does not 25 * thus the quantity is also random, useless. Showing 0.000000 does not
26 * deprive us from any useful info. */ 26 * deprive us from any useful info.
27 *
28 * SHOW_HWCLOCK_DIFF code in this file shows the difference between system
29 * and hw clock. It is useful, but not compatible with standard hwclock.
30 * Thus disabled.
31 */
27#define SHOW_HWCLOCK_DIFF 0 32#define SHOW_HWCLOCK_DIFF 0
28 33
29 34
@@ -40,13 +45,14 @@ static time_t read_rtc(const char **pp_rtcname, struct timeval *sys_tv, int utc)
40 rtc_read_tm(&tm, fd); 45 rtc_read_tm(&tm, fd);
41 46
42#if SHOW_HWCLOCK_DIFF 47#if SHOW_HWCLOCK_DIFF
43 int before; 48 {
44 before = tm.tm_sec; 49 int before = tm.tm_sec;
45 while (1) { 50 while (1) {
46 rtc_read_tm(&tm, fd); 51 rtc_read_tm(&tm, fd);
47 gettimeofday(sys_tv, NULL); 52 gettimeofday(sys_tv, NULL);
48 if (before != tm.tm_sec) 53 if (before != tm.tm_sec)
49 break; 54 break;
55 }
50 } 56 }
51#endif 57#endif
52 58
@@ -58,29 +64,32 @@ static time_t read_rtc(const char **pp_rtcname, struct timeval *sys_tv, int utc)
58 64
59static void show_clock(const char **pp_rtcname, int utc) 65static void show_clock(const char **pp_rtcname, int utc)
60{ 66{
67#if SHOW_HWCLOCK_DIFF
68 struct timeval sys_tv;
69#endif
61 time_t t; 70 time_t t;
62 char *cp; 71 char *cp;
63 72
64 t = read_rtc(pp_rtcname, &sys_tv, utc); 73 t = read_rtc(pp_rtcname, &sys_tv, utc);
65 cp = ctime(&t); 74 cp = ctime(&t);
66 strchrnul(cp, '\n')[0] = '\0'; 75 strchrnul(cp, '\n')[0] = '\0';
76#if !SHOW_HWCLOCK_DIFF
67 printf("%s 0.000000 seconds\n", cp); 77 printf("%s 0.000000 seconds\n", cp);
68 78#else
69#if SHOW_HWCLOCK_DIFF 79 {
70 struct timeval sys_tv; 80 long diff = sys_tv.tv_sec - t;
71 long diff; 81 if (diff < 0 /*&& tv.tv_usec != 0*/) {
72 diff = sys_tv.tv_sec - t; 82 /* Why? */
73 if (diff < 0 /*&& tv.tv_usec != 0*/) { 83 /* diff >= 0 is ok: diff < 0, can't just use tv.tv_usec: */
74 /* Why? */ 84 /* 45.520820 43.520820 */
75 /* diff >= 0 is ok: diff < 0, can't just use tv.tv_usec: */ 85 /* - 44.000000 - 45.000000 */
76 /* 45.520820 43.520820 */ 86 /* = 0.520820 = -1.479180, not -2.520820! */
77 /* - 44.000000 - 45.000000 */ 87 diff++;
78 /* = 0.520820 = -1.479180, not -2.520820! */ 88 /* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
79 diff++; 89 sys_tv.tv_usec = 999999 - sys_tv.tv_usec;
80 /* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */ 90 }
81 sys_tv.tv_usec = 999999 - sys_tv.tv_usec; 91 printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec);
82 } 92 }
83 printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec);
84#endif 93#endif
85} 94}
86 95