summaryrefslogtreecommitdiff
path: root/util-linux/hwclock.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/hwclock.c')
-rw-r--r--util-linux/hwclock.c60
1 files changed, 27 insertions, 33 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
index c4b793e..204a103 100644
--- a/util-linux/hwclock.c
+++ b/util-linux/hwclock.c
@@ -7,7 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-//#include <sys/ioctl.h>
#include <sys/utsname.h>
#include <getopt.h>
#include "libbb.h"
@@ -98,49 +97,42 @@ static void write_rtc(time_t t, int utc)
close(rtc);
}
-static int show_clock(int utc)
+static void show_clock(int utc)
{
- struct tm *ptm;
+ //struct tm *ptm;
time_t t;
- RESERVE_CONFIG_BUFFER(buffer, 64);
+ char *cp;
t = read_rtc(utc);
- ptm = localtime(&t); /* Sets 'tzname[]' */
+ //ptm = localtime(&t); /* Sets 'tzname[]' */
- safe_strncpy(buffer, ctime(&t), 64);
- if (buffer[0])
- buffer[strlen(buffer) - 1] = 0;
+ cp = ctime(&t);
+ if (cp[0])
+ cp[strlen(cp) - 1] = '\0';
- //printf("%s %.6f seconds %s\n", buffer, 0.0, utc ? "" : (ptm->tm_isdst ? tzname[1] : tzname[0]));
- printf( "%s %.6f seconds\n", buffer, 0.0);
- RELEASE_CONFIG_BUFFER(buffer);
-
- return 0;
+ //printf("%s %.6f seconds %s\n", cp, 0.0, utc ? "" : (ptm->tm_isdst ? tzname[1] : tzname[0]));
+ printf("%s 0.000000 seconds\n", cp);
}
-static int to_sys_clock(int utc)
+static void to_sys_clock(int utc)
{
- struct timeval tv = { 0, 0 };
+ struct timeval tv;
const struct timezone tz = { timezone/60 - 60*daylight, 0 };
tv.tv_sec = read_rtc(utc);
-
+ tv.tv_usec = 0;
if (settimeofday(&tv, &tz))
bb_perror_msg_and_die("settimeofday() failed");
-
- return 0;
}
-static int from_sys_clock(int utc)
+static void from_sys_clock(int utc)
{
- struct timeval tv = { 0, 0 };
- struct timezone tz = { 0, 0 };
-
- if (gettimeofday(&tv, &tz))
- bb_perror_msg_and_die("gettimeofday() failed");
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ //if (gettimeofday(&tv, NULL))
+ // bb_perror_msg_and_die("gettimeofday() failed");
write_rtc(tv.tv_sec, utc);
- return 0;
}
#ifdef CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS
@@ -182,8 +174,8 @@ static int check_utc(void)
#define HWCLOCK_OPT_SYSTOHC 0x10
#define HWCLOCK_OPT_RTCFILE 0x20
-int hwclock_main(int argc, char **argv );
-int hwclock_main(int argc, char **argv )
+int hwclock_main(int argc, char **argv);
+int hwclock_main(int argc, char **argv)
{
unsigned opt;
int utc;
@@ -210,12 +202,14 @@ int hwclock_main(int argc, char **argv )
utc = check_utc();
if (opt & HWCLOCK_OPT_HCTOSYS) {
- return to_sys_clock(utc);
+ to_sys_clock(utc);
+ return 0;
}
- else if (opt & HWCLOCK_OPT_SYSTOHC) {
- return from_sys_clock(utc);
- } else {
- /* default HWCLOCK_OPT_SHOW */
- return show_clock(utc);
+ if (opt & HWCLOCK_OPT_SYSTOHC) {
+ from_sys_clock(utc);
+ return 0;
}
+ /* default HWCLOCK_OPT_SHOW */
+ show_clock(utc);
+ return 0;
}