Index: head/usr.bin/time/time.c =================================================================== --- head/usr.bin/time/time.c +++ head/usr.bin/time/time.c @@ -58,18 +58,19 @@ #include #include #include +#include #include static int getstathz(void); static void humantime(FILE *, long, long); -static void showtime(FILE *, struct timeval *, struct timeval *, +static void showtime(FILE *, struct timespec *, struct timespec *, struct rusage *); static void siginfo(int); static void usage(void); static sig_atomic_t siginfo_recvd; static char decimal_point; -static struct timeval before_tv; +static struct timespec before_ts; static int hflag, pflag; int @@ -80,7 +81,7 @@ pid_t pid; struct rlimit rl; struct rusage ru; - struct timeval after; + struct timespec after; char *ofn = NULL; FILE *out = stderr; @@ -120,7 +121,8 @@ setvbuf(out, (char *)NULL, _IONBF, (size_t)0); } - (void)gettimeofday(&before_tv, NULL); + if (clock_gettime(CLOCK_REALTIME, &before_ts)) + err(1, "clock_gettime"); switch(pid = fork()) { case -1: /* error */ err(1, "time"); @@ -139,16 +141,18 @@ while (wait4(pid, &status, 0, &ru) != pid) { if (siginfo_recvd) { siginfo_recvd = 0; - (void)gettimeofday(&after, NULL); + if (clock_gettime(CLOCK_REALTIME, &after)) + err(1, "clock_gettime"); getrusage(RUSAGE_CHILDREN, &ru); - showtime(stdout, &before_tv, &after, &ru); + showtime(stdout, &before_ts, &after, &ru); } } - (void)gettimeofday(&after, NULL); + if (clock_gettime(CLOCK_REALTIME, &after)) + err(1, "clock_gettime"); if ( ! WIFEXITED(status)) warnx("command terminated abnormally"); exitonsig = WIFSIGNALED(status) ? WTERMSIG(status) : 0; - showtime(out, &before_tv, &after, &ru); + showtime(out, &before_ts, &after, &ru); if (lflag) { int hz = getstathz(); u_long ticks; @@ -237,7 +241,7 @@ } static void -humantime(FILE *out, long sec, long usec) +humantime(FILE *out, long sec, long centisec) { long days, hrs, mins; @@ -255,18 +259,18 @@ fprintf(out, "%ldh", hrs); if (mins) fprintf(out, "%ldm", mins); - fprintf(out, "%ld%c%02lds", sec, decimal_point, usec); + fprintf(out, "%ld%c%02lds", sec, decimal_point, centisec); } static void -showtime(FILE *out, struct timeval *before, struct timeval *after, +showtime(FILE *out, struct timespec *before, struct timespec *after, struct rusage *ru) { after->tv_sec -= before->tv_sec; - after->tv_usec -= before->tv_usec; - if (after->tv_usec < 0) - after->tv_sec--, after->tv_usec += 1000000; + after->tv_nsec -= before->tv_nsec; + if (after->tv_nsec < 0) + after->tv_sec--, after->tv_nsec += 1000000000; if (pflag) { /* POSIX wants output that must look like @@ -274,7 +278,7 @@ at least two digits after the radix. */ fprintf(out, "real %jd%c%02ld\n", (intmax_t)after->tv_sec, decimal_point, - after->tv_usec/10000); + after->tv_nsec/10000000); fprintf(out, "user %jd%c%02ld\n", (intmax_t)ru->ru_utime.tv_sec, decimal_point, ru->ru_utime.tv_usec/10000); @@ -282,7 +286,7 @@ (intmax_t)ru->ru_stime.tv_sec, decimal_point, ru->ru_stime.tv_usec/10000); } else if (hflag) { - humantime(out, after->tv_sec, after->tv_usec/10000); + humantime(out, after->tv_sec, after->tv_nsec/10000000); fprintf(out, " real\t"); humantime(out, ru->ru_utime.tv_sec, ru->ru_utime.tv_usec/10000); fprintf(out, " user\t"); @@ -291,7 +295,7 @@ } else { fprintf(out, "%9jd%c%02ld real ", (intmax_t)after->tv_sec, decimal_point, - after->tv_usec/10000); + after->tv_nsec/10000000); fprintf(out, "%9jd%c%02ld user ", (intmax_t)ru->ru_utime.tv_sec, decimal_point, ru->ru_utime.tv_usec/10000);