summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2012-09-01 14:45:15 +0000
committered <ed@FreeBSD.org>2012-09-01 14:45:15 +0000
commit02dcf28b5875df173bef8c14a9ddd3d3ce67c5d4 (patch)
tree496a0b9a3b14c27d50e1ae3b28265ecf5c2023f2 /usr.bin
parenta6edc1e4b7ca5750cf84fb6a6b048b796c0cc77f (diff)
downloadFreeBSD-src-02dcf28b5875df173bef8c14a9ddd3d3ce67c5d4.zip
FreeBSD-src-02dcf28b5875df173bef8c14a9ddd3d3ce67c5d4.tar.gz
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.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/lock/lock.c33
-rw-r--r--usr.bin/mail/util.c2
-rw-r--r--usr.bin/systat/ifstat.c3
-rw-r--r--usr.bin/time/time.c6
4 files changed, 20 insertions, 24 deletions
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 <sys/param.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include <sys/signal.h>
#include <sys/consio.h>
+
#include <err.h>
#include <ctype.h>
#include <errno.h>
@@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <syslog.h>
#include <termios.h>
+#include <time.h>
#include <unistd.h>
#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);
}
OpenPOWER on IntegriCloud