From 02dcf28b5875df173bef8c14a9ddd3d3ce67c5d4 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 1 Sep 2012 14:45:15 +0000 Subject: Rework all non-contributed files that use `struct timezone'. This structure is not part of POSIX. According to POSIX, gettimeofday() has the following prototype: int gettimeofday(struct timeval *restrict tp, void *restrict tzp); Also, POSIX states that gettimeofday() shall return 0 (as long as tzp is not used). Remove dead error handling code. Also use NULL for a nul-pointer instead of integer 0. While there, change all pieces of code that only use tv_sec to use time(3), as this provides less overhead. --- usr.bin/lock/lock.c | 33 +++++++++++++++------------------ usr.bin/mail/util.c | 2 +- usr.bin/systat/ifstat.c | 3 +-- usr.bin/time/time.c | 6 +++--- 4 files changed, 20 insertions(+), 24 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/lock/lock.c b/usr.bin/lock/lock.c index 3f23a98..0382e83 100644 --- a/usr.bin/lock/lock.c +++ b/usr.bin/lock/lock.c @@ -54,9 +54,9 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include + #include #include #include @@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #define TIMEOUT 15 @@ -89,10 +90,9 @@ int main(int argc, char **argv) { struct passwd *pw; - struct timeval timval; - time_t timval_sec; struct itimerval ntimer, otimer; struct tm *timp; + time_t timval; int ch, failures, sectimeout, usemine, vtylock; char *ap, *cryptpw, *mypw, *ttynam, *tzn; char hostname[MAXHOSTNAMELEN], s[BUFSIZ], s1[BUFSIZ]; @@ -138,11 +138,9 @@ main(int argc, char **argv) errx(1, "not a terminal?"); if (strncmp(ttynam, _PATH_DEV, strlen(_PATH_DEV)) == 0) ttynam += strlen(_PATH_DEV); - if (gettimeofday(&timval, (struct timezone *)NULL)) - err(1, "gettimeofday"); - nexttime = timval.tv_sec + (sectimeout * 60); - timval_sec = timval.tv_sec; - timp = localtime(&timval_sec); + timval = time(NULL); + nexttime = timval + (sectimeout * 60); + timp = localtime(&timval); ap = asctime(timp); tzn = timp->tm_zone; @@ -256,17 +254,16 @@ usage(void) static void hi(int signo __unused) { - struct timeval timval; + time_t timval; - if (!gettimeofday(&timval, (struct timezone *)NULL)) { - (void)printf("lock: type in the unlock key. "); - if (no_timeout) { - (void)putchar('\n'); - } else { - (void)printf("timeout in %jd:%jd minutes\n", - (intmax_t)(nexttime - timval.tv_sec) / 60, - (intmax_t)(nexttime - timval.tv_sec) % 60); - } + timval = time(NULL); + (void)printf("lock: type in the unlock key. "); + if (no_timeout) { + (void)putchar('\n'); + } else { + (void)printf("timeout in %jd:%jd minutes\n", + (intmax_t)(nexttime - timval) / 60, + (intmax_t)(nexttime - timval) % 60); } } diff --git a/usr.bin/mail/util.c b/usr.bin/mail/util.c index c90fe90..4e3a0f6 100644 --- a/usr.bin/mail/util.c +++ b/usr.bin/mail/util.c @@ -324,7 +324,7 @@ alter(char *name) if (stat(name, &sb)) return; - (void)gettimeofday(&tv[0], (struct timezone *)NULL); + (void)gettimeofday(&tv[0], NULL); tv[0].tv_sec++; TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtim); (void)utimes(name, tv); diff --git a/usr.bin/systat/ifstat.c b/usr.bin/systat/ifstat.c index fc853b0..3e45499 100644 --- a/usr.bin/systat/ifstat.c +++ b/usr.bin/systat/ifstat.c @@ -247,8 +247,7 @@ fetchifstat(void) old_outb = ifp->if_mib.ifmd_data.ifi_obytes; ifp->tv_lastchanged = ifp->if_mib.ifmd_data.ifi_lastchange; - if (gettimeofday(&new_tv, (struct timezone *)0) != 0) - IFSTAT_ERR(2, "error getting time of day"); + (void)gettimeofday(&new_tv, NULL); (void)getifmibdata(ifp->if_row, &ifp->if_mib); new_inb = ifp->if_mib.ifmd_data.ifi_ibytes; diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c index 2cb7f13..ebee542 100644 --- a/usr.bin/time/time.c +++ b/usr.bin/time/time.c @@ -117,7 +117,7 @@ main(int argc, char **argv) setvbuf(out, (char *)NULL, _IONBF, (size_t)0); } - gettimeofday(&before_tv, (struct timezone *)NULL); + (void)gettimeofday(&before_tv, NULL); switch(pid = fork()) { case -1: /* error */ err(1, "time"); @@ -134,7 +134,7 @@ main(int argc, char **argv) (void)signal(SIGQUIT, SIG_IGN); (void)signal(SIGINFO, siginfo); while (wait4(pid, &status, 0, &ru) != pid); - gettimeofday(&after, (struct timezone *)NULL); + (void)gettimeofday(&after, NULL); if ( ! WIFEXITED(status)) warnx("command terminated abnormally"); exitonsig = WIFSIGNALED(status) ? WTERMSIG(status) : 0; @@ -297,7 +297,7 @@ siginfo(int sig __unused) struct timeval after; struct rusage ru; - gettimeofday(&after, (struct timezone *)NULL); + (void)gettimeofday(&after, NULL); getrusage(RUSAGE_CHILDREN, &ru); showtime(stdout, &before_tv, &after, &ru); } -- cgit v1.1