From: Philipp Gesang Date: Mon, 3 Feb 2020 14:35:38 +0000 (+0100) Subject: replace obsolete call to ftime(3) X-Git-Url: http://developer.intra2net.com/git/?p=libi2ncommon;a=commitdiff_plain;h=4f1a78cac519d257c52cf3677175689b70f796c0 replace obsolete call to ftime(3) ftime() and timeb.h have been deprecated since POSIX 2008 and will be removed in future versions of glibc [0]. Replace them with (probably faster) calls to clock_gettime(2). [0] https://sourceware.org/ml/libc-announce/2020/msg00001.html --- diff --git a/src/timefunc.cpp b/src/timefunc.cpp index a4d38b8..6f4ffb5 100644 --- a/src/timefunc.cpp +++ b/src/timefunc.cpp @@ -38,7 +38,6 @@ on this file might be covered by the GNU General Public License. #include #include #include -#include #include #include @@ -59,12 +58,17 @@ using namespace std; double prec_time(void) { - struct timeb tb; - double ret; + struct timespec ts = { 0 }; + double ret = 0.0; - ftime(&tb); + if (clock_gettime(CLOCK_REALTIME_COARSE, &ts) == -1) { + /* Something’s wrong on the kernel end! */ + return ret; + } - ret=tb.time+(static_cast(tb.millitm)/1000); + ret = static_cast(ts.tv_sec); + ret += static_cast(ts.tv_nsec) + / static_cast(TIME_CONST_FACTOR_NANO); return ret; }