#include "timestamp.h"
#ifdef _WIN32
#include <windows.h>
#else
#include <time.h>
#if defined(__APPLE__) && !defined(CLOCK_MONOTONIC)
#include <sys/time.h>
#define CLOCK_MONOTONIC 0
int clock_gettime(int clk_id, struct timespec *t) {
(void)clk_id;
struct timeval now;
if (gettimeofday(&now, NULL))
return -1;
t->tv_sec = now.tv_sec;
t->tv_nsec = now.tv_usec * 1000;
return 0;
}
#endif
#endif
timestamp_t current_timestamp() {
#ifdef _WIN32
return (timestamp_t)GetTickCount();
#else
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
return 0;
return (timestamp_t)ts.tv_sec * 1000 + (timestamp_t)ts.tv_nsec / 1000000;
#endif
}