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
#include <time.h>
#include <unistd.h>
#include <string.h>
-#include <sys/timeb.h>
#include <timefunc.hxx>
#include <i18n.h>
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<float>(tb.millitm)/1000);
+ ret = static_cast<double>(ts.tv_sec);
+ ret += static_cast<double>(ts.tv_nsec)
+ / static_cast<double>(TIME_CONST_FACTOR_NANO);
return ret;
}