aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-02-09 17:47:29 -0600
committerRob Landley <rob@landley.net>2015-02-09 17:47:29 -0600
commitfb49bf09694439102959fbce896404ab819bdf99 (patch)
tree1b8c22413db48219b29941c2d4b443de6d884f44 /toys
parent2c9b0e3009cf76e9d7fca772945711675678d181 (diff)
downloadtoybox-fb49bf09694439102959fbce896404ab819bdf99.tar.gz
One more cleanup pass on hwclock factoring out common code.
Diffstat (limited to 'toys')
-rw-r--r--toys/pending/hwclock.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/toys/pending/hwclock.c b/toys/pending/hwclock.c
index c3dabdfb..d9ced6fb 100644
--- a/toys/pending/hwclock.c
+++ b/toys/pending/hwclock.c
@@ -98,10 +98,11 @@ void hwclock_main()
}
}
- if (toys.optflags & FLAG_w) {
+ if (toys.optflags & (FLAG_w|FLAG_t))
if (gettimeofday(&timeval, 0)
|| (TT.utc ? gmtime_r : localtime_r)(&timeval.tv_sec, &tm)) goto bad;
+ if (toys.optflags & FLAG_w) {
/* The value of tm_isdst will positive if daylight saving time is in effect,
* zero if it is not and negative if the information is not available.
* todo: so why isn't this negative...? */
@@ -110,20 +111,13 @@ void hwclock_main()
} else if (toys.optflags & FLAG_s) {
tzone.tz_minuteswest = timezone / 60 - 60 * daylight;
timeval.tv_sec = time;
- timeval.tv_usec = 0;
- tzone.tz_dsttime = 0;
- if (settimeofday(&timeval, &tzone)) goto bad;
+ timeval.tv_usec = 0; // todo: fixit
} else if (toys.optflags & FLAG_t) {
- if (gettimeofday(&timeval, NULL) || !localtime_r(&timeval.tv_sec, &tm))
- goto bad;
// Adjust seconds for timezone and daylight saving time
// extern long timezone is defined in header sys/time.h
tzone.tz_minuteswest = timezone / 60;
if (tm.tm_isdst) tzone.tz_minuteswest -= 60;
- if (gettimeofday(&timeval, NULL)) goto bad;
if (!TT.utc) timeval.tv_sec += tzone.tz_minuteswest * 60;
- tzone.tz_dsttime = 0;
- if (settimeofday(&timeval, &tzone)) goto bad;
} else {
char *c = ctime(&time), *s = strrchr(c, '\n');
@@ -131,6 +125,10 @@ void hwclock_main()
// TODO: implement this.
xprintf("%s 0.000000 seconds\n", c);
}
+ if (toys.optflags & (FLAG_t|FLAG_s)) {
+ tzone.tz_dsttime = 0;
+ if (settimeofday(&timeval, &tzone)) goto bad;
+ }
if (fd != -1) close(fd);