From 1dfeccb761e64b8879aa75aad68545dbf5f49aaa Mon Sep 17 00:00:00 2001 From: cheloha Date: Sat, 23 Dec 2017 20:53:07 +0000 Subject: [PATCH] As we only use the .tv_sec field, simplify gettimeofday(2) -> time(3). ok tb@ jca@ --- games/pom/pom.c | 12 +++--------- usr.bin/pr/pr.c | 30 +++++------------------------- usr.sbin/arp/arp.c | 17 +++++++---------- 3 files changed, 15 insertions(+), 44 deletions(-) diff --git a/games/pom/pom.c b/games/pom/pom.c index 55ce415a182..b57214e9ce3 100644 --- a/games/pom/pom.c +++ b/games/pom/pom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pom.c,v 1.25 2016/12/01 20:08:59 fcambus Exp $ */ +/* $OpenBSD: pom.c,v 1.26 2017/12/23 20:53:07 cheloha Exp $ */ /* $NetBSD: pom.c,v 1.6 1996/02/06 22:47:29 jtc Exp $ */ /* @@ -44,7 +44,6 @@ * */ -#include #include #include #include @@ -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); diff --git a/usr.bin/pr/pr.c b/usr.bin/pr/pr.c index 08941e13d16..0342df907aa 100644 --- a/usr.bin/pr/pr.c +++ b/usr.bin/pr/pr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pr.c,v 1.40 2017/11/02 09:52:04 jca Exp $ */ +/* $OpenBSD: pr.c,v 1.41 2017/12/23 20:53:07 cheloha Exp $ */ /*- * Copyright (c) 1991 Keith Muller. @@ -34,7 +34,6 @@ */ #include -#include #include #include @@ -45,6 +44,7 @@ #include #include #include +#include #include #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 **fname, char *buf, int dt) *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 **fname, char *buf, int dt) ++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 **fname, char *buf, int dt) 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) { diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c index 59180d01527..886a0fbc6b1 100644 --- a/usr.sbin/arp/arp.c +++ b/usr.sbin/arp/arp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arp.c,v 1.79 2017/04/19 05:36:12 natano Exp $ */ +/* $OpenBSD: arp.c,v 1.80 2017/12/23 20:53:07 cheloha Exp $ */ /* $NetBSD: arp.c,v 1.12 1995/04/24 13:25:18 cgd Exp $ */ /* @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -57,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -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, struct sockaddr_inarp *sin, 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, struct sockaddr_inarp *sin, 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"); -- 2.20.1