From ed1d13df04198c8974c20dae7729d60fb8e0a117 Mon Sep 17 00:00:00 2001 From: cheloha Date: Sat, 23 Dec 2017 20:58:14 +0000 Subject: [PATCH] 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@ --- bin/date/date.c | 14 ++++++-------- 1 file 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", ""); -- 2.20.1