diff --git a/.vscode/settings.json b/.vscode/settings.json index 12b59a0..769b77f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,6 +21,7 @@ "snowid_checkpoint.h": "c", "unistd.h": "c", "__locale": "c", - "if_dl.h": "c" + "if_dl.h": "c", + "ctime": "c" } } \ No newline at end of file diff --git a/snowid_util.c b/snowid_util.c index 9ece0a0..23eca9c 100644 --- a/snowid_util.c +++ b/snowid_util.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include @@ -101,19 +101,17 @@ bool get_hw_addr_as_binary(uint64_t *workerid, char *interface) bool get_current_ts(uint64_t *result) { - time_t t; + struct timeval now; if (result == NULL) { return false; } - t = time(NULL); - - if (t == (time_t)-1) { + if (gettimeofday(&now, NULL) == -1) { return false; } - *result = (uint64_t)t; + *result = (uint64_t)((now.tv_sec * 1000) + (now.tv_usec / 1000)); return true; } \ No newline at end of file