summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index defbdb0..714217f 100644
--- a/src/util.c
+++ b/src/util.c
@@ -18,19 +18,60 @@
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
#include <dlog.h>
#include "util.h"
#include "debug.h"
-double util_get_timestamp(void)
+int errno;
+#if defined(_USE_ECORE_TIME_GET)
+static struct {
+ clockid_t type;
+} s_info = {
+ .type = CLOCK_MONOTONIC,
+};
+#endif
+
+double util_timestamp(void)
{
+#ifdef _USE_ECORE_TIME_GET
+ struct timespec ts;
+
+ do {
+ if (clock_gettime(s_info.type, &ts) == 0) {
+ return ts.tv_sec + ts.tv_nsec / 1000000000.0f;
+ }
+
+ ErrPrint("%d: %s\n", s_info.type, strerror(errno));
+ if (s_info.type == CLOCK_MONOTONIC) {
+ s_info.type = CLOCK_REALTIME;
+ } else if (s_info.type == CLOCK_REALTIME) {
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) < 0) {
+ ErrPrint("gettimeofday: %s\n", strerror(errno));
+ break;
+ }
+
+ return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
+ }
+ } while (1);
+
+ return 0.0f;
+#else
struct timeval tv;
- gettimeofday(&tv, NULL);
+ if (gettimeofday(&tv, NULL) < 0) {
+ ErrPrint("gettimeofday: %s\n", strerror(errno));
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ }
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
+#endif
}
const char *util_basename(const char *name)