Wed May 26 20:19:51 2021 UTC ()
tool changes


(christos)
diff -r1.15 -r1.16 src/bin/date/Makefile
diff -r1.61 -r1.62 src/bin/date/date.c

cvs diff -r1.15 -r1.16 src/bin/date/Makefile (expand / switch to unified diff)

--- src/bin/date/Makefile 2011/08/14 10:53:16 1.15
+++ src/bin/date/Makefile 2021/05/26 20:19:51 1.16
@@ -1,12 +1,17 @@ @@ -1,12 +1,17 @@
1# $NetBSD: Makefile,v 1.15 2011/08/14 10:53:16 christos Exp $ 1# $NetBSD: Makefile,v 1.16 2021/05/26 20:19:51 christos Exp $
2# @(#)Makefile 8.1 (Berkeley) 5/31/93 2# @(#)Makefile 8.1 (Berkeley) 5/31/93
3 3
 4.include <bsd.init.mk>
 5
4PROG= date 6PROG= date
5SRCS= date.c netdate.c 7SRCS= date.c
 8.if !defined(HOSTPROG)
 9SRCS+= netdate.c
6DPADD+= ${LIBUTIL} 10DPADD+= ${LIBUTIL}
7LDADD+= -lutil 11LDADD+= -lutil
 12.endif
8CPPFLAGS+=-I${.CURDIR} 13CPPFLAGS+=-I${.CURDIR}
9 14
10COPTS.date.c = -Wno-format-nonliteral 15COPTS.date.c = -Wno-format-nonliteral
11 16
12.include <bsd.prog.mk> 17.include <bsd.prog.mk>

cvs diff -r1.61 -r1.62 src/bin/date/date.c (expand / switch to unified diff)

--- src/bin/date/date.c 2014/09/01 21:42:21 1.61
+++ src/bin/date/date.c 2021/05/26 20:19:51 1.62
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: date.c,v 1.61 2014/09/01 21:42:21 dholland Exp $ */ 1/* $NetBSD: date.c,v 1.62 2021/05/26 20:19:51 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1985, 1987, 1988, 1993 4 * Copyright (c) 1985, 1987, 1988, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -19,38 +19,42 @@ @@ -19,38 +19,42 @@
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
 32#if HAVE_NBTOOL_CONFIG_H
 33#include "nbtool_config.h"
 34#endif
 35
32#include <sys/cdefs.h> 36#include <sys/cdefs.h>
33#ifndef lint 37#ifndef lint
34__COPYRIGHT( 38__COPYRIGHT(
35"@(#) Copyright (c) 1985, 1987, 1988, 1993\ 39"@(#) Copyright (c) 1985, 1987, 1988, 1993\
36 The Regents of the University of California. All rights reserved."); 40 The Regents of the University of California. All rights reserved.");
37#endif /* not lint */ 41#endif /* not lint */
38 42
39#ifndef lint 43#ifndef lint
40#if 0 44#if 0
41static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95"; 45static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
42#else 46#else
43__RCSID("$NetBSD: date.c,v 1.61 2014/09/01 21:42:21 dholland Exp $"); 47__RCSID("$NetBSD: date.c,v 1.62 2021/05/26 20:19:51 christos Exp $");
44#endif 48#endif
45#endif /* not lint */ 49#endif /* not lint */
46 50
47#include <sys/param.h> 51#include <sys/param.h>
48#include <sys/time.h> 52#include <sys/time.h>
49 53
50#include <ctype.h> 54#include <ctype.h>
51#include <err.h> 55#include <err.h>
52#include <fcntl.h> 56#include <fcntl.h>
53#include <errno.h> 57#include <errno.h>
54#include <locale.h> 58#include <locale.h>
55#include <stdio.h> 59#include <stdio.h>
56#include <stdlib.h> 60#include <stdlib.h>
@@ -80,33 +84,38 @@ main(int argc, char *argv[]) @@ -80,33 +84,38 @@ main(int argc, char *argv[])
80 long long val; 84 long long val;
81 struct tm *tm; 85 struct tm *tm;
82 86
83 setprogname(argv[0]); 87 setprogname(argv[0]);
84 (void)setlocale(LC_ALL, ""); 88 (void)setlocale(LC_ALL, "");
85 89
86 while ((ch = getopt(argc, argv, "ad:jnr:u")) != -1) { 90 while ((ch = getopt(argc, argv, "ad:jnr:u")) != -1) {
87 switch (ch) { 91 switch (ch) {
88 case 'a': /* adjust time slowly */ 92 case 'a': /* adjust time slowly */
89 aflag = 1; 93 aflag = 1;
90 nflag = 1; 94 nflag = 1;
91 break; 95 break;
92 case 'd': 96 case 'd':
 97#ifndef HAVE_NBTOOL_CONFIG_H
93 rflag = 1; 98 rflag = 1;
94 tval = parsedate(optarg, NULL, NULL); 99 tval = parsedate(optarg, NULL, NULL);
95 if (tval == -1) { 100 if (tval == -1) {
96 errx(EXIT_FAILURE, 101 errx(EXIT_FAILURE,
97 "%s: Unrecognized date format", optarg); 102 "%s: Unrecognized date format", optarg);
98 } 103 }
99 break; 104 break;
 105#else
 106 errx(EXIT_FAILURE,
 107 "-d not supported in the tool version");
 108#endif
100 case 'j': /* don't set time */ 109 case 'j': /* don't set time */
101 jflag = 1; 110 jflag = 1;
102 break; 111 break;
103 case 'n': /* don't set network */ 112 case 'n': /* don't set network */
104 nflag = 1; 113 nflag = 1;
105 break; 114 break;
106 case 'r': /* user specified seconds */ 115 case 'r': /* user specified seconds */
107 if (optarg[0] == '\0') { 116 if (optarg[0] == '\0') {
108 errx(EXIT_FAILURE, "<empty>: Invalid number"); 117 errx(EXIT_FAILURE, "<empty>: Invalid number");
109 } 118 }
110 errno = 0; 119 errno = 0;
111 val = strtoll(optarg, &buf, 0); 120 val = strtoll(optarg, &buf, 0);
112 if (errno) { 121 if (errno) {
@@ -320,42 +329,46 @@ setthetime(const char *p) @@ -320,42 +329,46 @@ setthetime(const char *p)
320 /* convert broken-down time to UTC clock time */ 329 /* convert broken-down time to UTC clock time */
321 if ((new_time = mktime(lt)) == -1) { 330 if ((new_time = mktime(lt)) == -1) {
322 /* Can this actually happen? */ 331 /* Can this actually happen? */
323 err(EXIT_FAILURE, "%s: mktime", op); 332 err(EXIT_FAILURE, "%s: mktime", op);
324 } 333 }
325 334
326 /* if jflag is set, don't actually change the time, just return */ 335 /* if jflag is set, don't actually change the time, just return */
327 if (jflag) { 336 if (jflag) {
328 tval = new_time; 337 tval = new_time;
329 return; 338 return;
330 } 339 }
331 340
332 /* set the time */ 341 /* set the time */
 342#ifndef HAVE_NBTOOL_CONFIG_H
333 if (nflag || netsettime(new_time)) { 343 if (nflag || netsettime(new_time)) {
334 logwtmp("|", "date", ""); 344 logwtmp("|", "date", "");
335 if (aflag) { 345 if (aflag) {
336 tv.tv_sec = new_time - tval; 346 tv.tv_sec = new_time - tval;
337 tv.tv_usec = 0; 347 tv.tv_usec = 0;
338 if (adjtime(&tv, NULL)) 348 if (adjtime(&tv, NULL))
339 err(EXIT_FAILURE, "adjtime"); 349 err(EXIT_FAILURE, "adjtime");
340 } else { 350 } else {
341 tval = new_time; 351 tval = new_time;
342 tv.tv_sec = tval; 352 tv.tv_sec = tval;
343 tv.tv_usec = 0; 353 tv.tv_usec = 0;
344 if (settimeofday(&tv, NULL)) 354 if (settimeofday(&tv, NULL))
345 err(EXIT_FAILURE, "settimeofday"); 355 err(EXIT_FAILURE, "settimeofday");
346 } 356 }
347 logwtmp("{", "date", ""); 357 logwtmp("{", "date", "");
348 } 358 }
 359#else
 360 errx(EXIT_FAILURE, "Can't set the time in the tools version");
 361#endif
349 362
350 if ((p = getlogin()) == NULL) 363 if ((p = getlogin()) == NULL)
351 p = "???"; 364 p = "???";
352 syslog(LOG_AUTH | LOG_NOTICE, "date set by %s", p); 365 syslog(LOG_AUTH | LOG_NOTICE, "date set by %s", p);
353} 366}
354 367
355static void 368static void
356usage(void) 369usage(void)
357{ 370{
358 (void)fprintf(stderr, 371 (void)fprintf(stderr,
359 "Usage: %s [-ajnu] [-d date] [-r seconds] [+format]", 372 "Usage: %s [-ajnu] [-d date] [-r seconds] [+format]",
360 getprogname()); 373 getprogname());
361 (void)fprintf(stderr, " [[[[[[CC]yy]mm]dd]HH]MM[.SS]]\n"); 374 (void)fprintf(stderr, " [[[[[[CC]yy]mm]dd]HH]MM[.SS]]\n");