aboutsummaryrefslogtreecommitdiff
path: root/lib/xwrap.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-04-01 10:57:30 -0700
committerRob Landley <rob@landley.net>2020-04-01 18:13:11 -0500
commit85b02bddc0389487eaa8936de38441a1f95e08ea (patch)
tree095b9e49cee6b13bf82cf9eb84de22286780687d /lib/xwrap.c
parentc6c7fac0ad99833d56119595d9b3af0191c3407b (diff)
downloadtoybox-85b02bddc0389487eaa8936de38441a1f95e08ea.tar.gz
Add rtcwake.
Some of the bringup folks are debugging RTC issues and asked for this. Rather than duplicate the weird xtzset dance with mktime, I've factored that out into a new xmktime that takes a boolean for whether to use UTC or local time. Otherwise, the slight cleanup of hwclock.c is entirely optional. The only functional change there is that util-linux 2.34's hwclock uses ISO time format, which is the usual toybox preference anyway, so I've switched it over to that rather than ctime(3). Bug: http://b/152042947
Diffstat (limited to 'lib/xwrap.c')
-rw-r--r--lib/xwrap.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 555fbd5e..5f18f295 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -1077,3 +1077,16 @@ char *xgetline(FILE *fp, int *len)
return new;
}
+
+time_t xmktime(struct tm *tm, int utc)
+{
+ char *old_tz = utc ? xtzset("UTC0") : 0;
+ time_t result;
+
+ if ((result = mktime(tm)) < 0) error_exit("mktime");
+ if (utc) {
+ free(xtzset(old_tz));
+ free(old_tz);
+ }
+ return result;
+}