From 4f1a78cac519d257c52cf3677175689b70f796c0 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 3 Feb 2020 15:35:38 +0100 Subject: [PATCH] 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 --- src/timefunc.cpp | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) 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; } -- 1.7.1