Module Name: src Committed By: dholland Date: Sat Aug 27 18:48:30 UTC 2016
Modified Files: src/external/bsd/top/dist: utils.c Log Message: Be more careful/explicit with FP rounding when converting floating time to timeval. Also, don't truncate the seconds part to int for y2038. I've had this patch sitting around since 2010 and I completely forget what motivated it. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/external/bsd/top/dist/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/top/dist/utils.c diff -u src/external/bsd/top/dist/utils.c:1.4 src/external/bsd/top/dist/utils.c:1.5 --- src/external/bsd/top/dist/utils.c:1.4 Tue May 5 18:51:22 2009 +++ src/external/bsd/top/dist/utils.c Sat Aug 27 18:48:30 2016 @@ -41,6 +41,7 @@ #include "os.h" #include <ctype.h> +#include <math.h> #ifdef HAVE_STDARG_H #include <stdarg.h> #else @@ -711,8 +712,11 @@ diff_per_second(unsigned int x, unsigned void double2tv(struct timeval *tv, double d) { - tv->tv_sec = (int)d; - tv->tv_usec = (d - tv->tv_sec) * 1000000; + double di; + + di = floor(d); + tv->tv_sec = (time_t)di; + tv->tv_usec = (int)ceil((d - di) * 1000000.0); } static int debug_on = 0;