aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2018-04-04 17:06:50 +0200
committerDuncaen <mail@duncano.de>2018-04-04 17:32:08 +0200
commit70d6027531abf90536a67a0f95d14d85b64f7989 (patch)
tree3618afc668dbbcb6d5c2e0f0929efb72aa29d577
parent52435f6573f2747df0c41ebc2ba521a167d78af1 (diff)
downloadlobase-70d6027531abf90536a67a0f95d14d85b64f7989.tar.gz
bin/date: update to OPENBSD_6_3
-rw-r--r--bin/date/date.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/bin/date/date.c b/bin/date/date.c
index 922744b..3f53cc7 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.52 2018/02/13 17:28:11 cheloha Exp $ */
/* $NetBSD: date.c,v 1.11 1995/09/07 06:21:05 jtc Exp $ */
/*
@@ -36,6 +36,7 @@
#include <ctype.h>
#include <err.h>
#include <fcntl.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -78,7 +79,9 @@ main(int argc, char *argv[])
break;
case 'r': /* user specified seconds */
rflag = 1;
- tval = atoll(optarg);
+ tval = strtonum(optarg, LLONG_MIN, LLONG_MAX, &errstr);
+ if (errstr)
+ errx(1, "seconds is %s: %s", errstr, optarg);
break;
case 'u': /* do everything in UTC */
if (setenv("TZ", "UTC", 1) == -1)
@@ -153,6 +156,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 +229,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 {
#ifdef HAVE_WTMP
#ifndef SMALL