diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-07-08 06:40:25 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-07-08 06:40:25 +0200 |
commit | 319b8bb3558ec4149f8653c1ff147d4ca8ba0217 (patch) | |
tree | 05ec7f5b136bc88d15fe8aaee056b6b541d265c0 | |
parent | db43d3d418fd228367594c926f206e7d7fe7b1ab (diff) | |
download | busybox-w32-319b8bb3558ec4149f8653c1ff147d4ca8ba0217.tar.gz busybox-w32-319b8bb3558ec4149f8653c1ff147d4ca8ba0217.tar.bz2 busybox-w32-319b8bb3558ec4149f8653c1ff147d4ca8ba0217.zip |
hwclock: use locale-specific date output format
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/hwclock.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index 3e2c2aae3..6b4e29bfa 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -60,25 +60,31 @@ static void show_clock(const char **pp_rtcname, int utc) | |||
60 | #if SHOW_HWCLOCK_DIFF | 60 | #if SHOW_HWCLOCK_DIFF |
61 | struct timeval sys_tv; | 61 | struct timeval sys_tv; |
62 | #endif | 62 | #endif |
63 | time_t t; | 63 | time_t t = read_rtc(pp_rtcname, &sys_tv, utc); |
64 | char *cp; | ||
65 | 64 | ||
66 | t = read_rtc(pp_rtcname, &sys_tv, utc); | 65 | #if ENABLE_LOCALE_SUPPORT |
67 | cp = ctime(&t); | 66 | /* Standard hwclock uses locale-specific output format */ |
67 | char cp[64]; | ||
68 | struct tm *ptm = localtime(&t); | ||
69 | strftime(cp, sizeof(cp), "%c", ptm); | ||
70 | #else | ||
71 | char *cp = ctime(&t); | ||
68 | strchrnul(cp, '\n')[0] = '\0'; | 72 | strchrnul(cp, '\n')[0] = '\0'; |
73 | #endif | ||
74 | |||
69 | #if !SHOW_HWCLOCK_DIFF | 75 | #if !SHOW_HWCLOCK_DIFF |
70 | printf("%s 0.000000 seconds\n", cp); | 76 | printf("%s 0.000000 seconds\n", cp); |
71 | #else | 77 | #else |
72 | { | 78 | { |
73 | long diff = sys_tv.tv_sec - t; | 79 | long diff = sys_tv.tv_sec - t; |
74 | if (diff < 0 /*&& tv.tv_usec != 0*/) { | 80 | if (diff < 0 /*&& tv.tv_usec != 0*/) { |
75 | /* Why? */ | 81 | /* Why we need diff++? */ |
76 | /* diff >= 0 is ok: diff < 0, can't just use tv.tv_usec: */ | 82 | /* diff >= 0 is ok: | diff < 0, can't just use tv.tv_usec: */ |
77 | /* 45.520820 43.520820 */ | 83 | /* 45.520820 | 43.520820 */ |
78 | /* - 44.000000 - 45.000000 */ | 84 | /* - 44.000000 | - 45.000000 */ |
79 | /* = 1.520820 = -1.479180, not -2.520820! */ | 85 | /* = 1.520820 | = -1.479180, not -2.520820! */ |
80 | diff++; | 86 | diff++; |
81 | /* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */ | 87 | /* Should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */ |
82 | sys_tv.tv_usec = 999999 - sys_tv.tv_usec; | 88 | sys_tv.tv_usec = 999999 - sys_tv.tv_usec; |
83 | } | 89 | } |
84 | printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec); | 90 | printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec); |