replace obsolete call to ftime(3)
[libi2ncommon] / src / timefunc.cpp
index a4d38b8..6f4ffb5 100644 (file)
@@ -38,7 +38,6 @@ on this file might be covered by the GNU General Public License.
 #include <time.h>
 #include <unistd.h>
 #include <string.h>
-#include <sys/timeb.h>
 
 #include <timefunc.hxx>
 #include <i18n.h>
@@ -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<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;
 }