diff options
author | cheloha <cheloha@cvs.openbsd.org> | 2017-12-23 20:58:15 +0000 |
---|---|---|
committer | cheloha <cheloha@cvs.openbsd.org> | 2017-12-23 20:58:15 +0000 |
commit | 11864459746eb843832b0c50f3240a053d3ae023 (patch) | |
tree | 502afd48a14239f01daeeb0773ac25142b521765 /bin/date | |
parent | 24742988183dcde580f2ff0832bb5c25e648798e (diff) |
As we only use the .tv_sec field, simplify gettimeofday(2) -> time(3).
While here, use err(3) instead of errx(3) if adjtime(2) fails.
Discussed/tweaked with/by tb@ and jca@.
ok tb@ jca@
Diffstat (limited to 'bin/date')
-rw-r--r-- | bin/date/date.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/bin/date/date.c b/bin/date/date.c index 65d89e0d404..087da9602da 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -1,4 +1,4 @@ -/* $OpenBSD: date.c,v 1.50 2016/10/19 18:20:25 schwarze Exp $ */ +/* $OpenBSD: date.c,v 1.51 2017/12/23 20:58:14 cheloha Exp $ */ /* $NetBSD: date.c,v 1.11 1995/09/07 06:21:05 jtc Exp $ */ /* @@ -153,6 +153,7 @@ setthetime(char *p) struct tm *lt; struct timeval tv; char *dot, *t; + time_t now; int yearset = 0; for (t = p, dot = NULL; *t; ++t) { @@ -225,15 +226,12 @@ setthetime(char *p) /* set the time */ if (slidetime) { - struct timeval tv_current; - - if (gettimeofday(&tv_current, NULL) == -1) - err(1, "Could not get local time of day"); - - tv.tv_sec = tval - tv_current.tv_sec; + if ((now = time(NULL)) == -1) + err(1, "time"); + tv.tv_sec = tval - now; tv.tv_usec = 0; if (adjtime(&tv, NULL) == -1) - errx(1, "adjtime"); + err(1, "adjtime"); } else { #ifndef SMALL logwtmp("|", "date", ""); |