Hey, None of these programs make use of anything but the .tv_sec field in the timeval initialized by gettimeofday(2), so we can simplify the code some and just use time(3).
While here, in date(1) we ought to use err(3) instead of errx(3) if adjtime(2) fails. This: date: adjtime: Operation not permitted is considerably more useful than this: date: adjtime Of some note is that pom(6) was one of the last programs in base calling gettimeofday(2) with a non-NULL timezone argument. ok? -- Scott Cheloha Index: bin/date/date.c =================================================================== RCS file: /cvs/src/bin/date/date.c,v retrieving revision 1.50 diff -u -p -r1.50 date.c --- bin/date/date.c 19 Oct 2016 18:20:25 -0000 1.50 +++ bin/date/date.c 23 Dec 2017 01:16:16 -0000 @@ -225,15 +225,10 @@ 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; + tv.tv_sec = tval - time(NULL); tv.tv_usec = 0; if (adjtime(&tv, NULL) == -1) - errx(1, "adjtime"); + err(1, "adjtime"); } else { #ifndef SMALL logwtmp("|", "date", ""); Index: games/pom/pom.c =================================================================== RCS file: /cvs/src/games/pom/pom.c,v retrieving revision 1.25 diff -u -p -r1.25 pom.c --- games/pom/pom.c 1 Dec 2016 20:08:59 -0000 1.25 +++ games/pom/pom.c 23 Dec 2017 01:16:16 -0000 @@ -44,7 +44,6 @@ * */ -#include <sys/time.h> #include <ctype.h> #include <err.h> #include <math.h> @@ -73,8 +72,6 @@ __dead void badformat(void); int main(int argc, char *argv[]) { - struct timeval tp; - struct timezone tzp; struct tm *GMT; time_t tmpt; double days, today, tomorrow; @@ -89,11 +86,8 @@ main(int argc, char *argv[]) strftime(buf, sizeof(buf), "%a %Y %b %e %H:%M:%S (%Z)", localtime(&tmpt)); printf("%s: ", buf); - } else { - if (gettimeofday(&tp,&tzp)) - err(1, "gettimeofday"); - tmpt = tp.tv_sec; - } + } else + tmpt = time(NULL); GMT = gmtime(&tmpt); days = (GMT->tm_yday + 1) + ((GMT->tm_hour + (GMT->tm_min / 60.0) + (GMT->tm_sec / 3600.0)) / 24.0); Index: usr.bin/pr/pr.c =================================================================== RCS file: /cvs/src/usr.bin/pr/pr.c,v retrieving revision 1.40 diff -u -p -r1.40 pr.c --- usr.bin/pr/pr.c 2 Nov 2017 09:52:04 -0000 1.40 +++ usr.bin/pr/pr.c 23 Dec 2017 01:16:16 -0000 @@ -34,7 +34,6 @@ */ #include <sys/types.h> -#include <sys/time.h> #include <sys/stat.h> #include <ctype.h> @@ -45,6 +44,7 @@ #include <stdarg.h> #include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> #include "pr.h" @@ -1442,7 +1442,6 @@ FILE * nxtfile(int argc, char *argv[], char **fname, char *buf, int dt) { FILE *inf = NULL; - struct timeval tv; struct tm *timeptr = NULL; struct stat statbuf; time_t curtime; @@ -1463,14 +1462,7 @@ nxtfile(int argc, char *argv[], char **f *fname = FNAME; if (nohead) return(inf); - if (gettimeofday(&tv, NULL) < 0) { - ++errcnt; - ferrout("pr: cannot get time of day, %s\n", - strerror(errno)); - eoptind = argc - 1; - return(NULL); - } - curtime = tv.tv_sec; + curtime = time(NULL);; timeptr = localtime(&curtime); } for (; eoptind < argc; ++eoptind) { @@ -1487,13 +1479,7 @@ nxtfile(int argc, char *argv[], char **f ++eoptind; if (nohead || (dt && twice)) return(inf); - if (gettimeofday(&tv, NULL) < 0) { - ++errcnt; - ferrout("pr: cannot get time of day, %s\n", - strerror(errno)); - return(NULL); - } - curtime = tv.tv_sec; + curtime = time(NULL); timeptr = localtime(&curtime); } else { /* @@ -1518,13 +1504,7 @@ nxtfile(int argc, char *argv[], char **f return(inf); if (dt) { - if (gettimeofday(&tv, NULL) < 0) { - ++errcnt; - ferrout("pr: cannot get time of day, %s\n", - strerror(errno)); - return(NULL); - } - curtime = tv.tv_sec; + curtime = time(NULL); timeptr = localtime(&curtime); } else { if (fstat(fileno(inf), &statbuf) < 0) { Index: usr.sbin/arp/arp.c =================================================================== RCS file: /cvs/src/usr.sbin/arp/arp.c,v retrieving revision 1.79 diff -u -p -r1.79 arp.c --- usr.sbin/arp/arp.c 19 Apr 2017 05:36:12 -0000 1.79 +++ usr.sbin/arp/arp.c 23 Dec 2017 01:16:16 -0000 @@ -40,7 +40,6 @@ #include <sys/file.h> #include <sys/socket.h> #include <sys/sysctl.h> -#include <sys/time.h> #include <sys/ioctl.h> #include <net/bpf.h> #include <net/if.h> @@ -57,6 +56,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> #include <paths.h> #include <unistd.h> #include <limits.h> @@ -297,10 +297,7 @@ set(int argc, char *argv[]) doing_proxy = flags = export_only = 0; while (argc-- > 0) { if (strncmp(argv[0], "temp", 4) == 0) { - struct timeval now; - - gettimeofday(&now, 0); - expire_time = now.tv_sec + 20 * 60; + expire_time = time(NULL) + 20 * 60; if (flags & RTF_PERMANENT_ARP) { /* temp or permanent, not both */ usage(); @@ -526,9 +523,9 @@ print_entry(struct sockaddr_dl *sdl, str char ifix_buf[IFNAMSIZ], *ifname, *host; struct hostent *hp = NULL; int addrwidth, llwidth, ifwidth ; - struct timeval now; + time_t now; - gettimeofday(&now, 0); + now = time(NULL); if (nflag == 0) hp = gethostbyaddr((caddr_t)&(sin->sin_addr), @@ -558,9 +555,9 @@ print_entry(struct sockaddr_dl *sdl, str printf(" %-9.9s", "permanent"); else if (rtm->rtm_rmx.rmx_expire == 0) printf(" %-9.9s", "static"); - else if (rtm->rtm_rmx.rmx_expire > now.tv_sec) + else if (rtm->rtm_rmx.rmx_expire > now) printf(" %-9.9s", - sec2str(rtm->rtm_rmx.rmx_expire - now.tv_sec)); + sec2str(rtm->rtm_rmx.rmx_expire - now)); else printf(" %-9.9s", "expired");