Skip to content

Commit

Permalink
* fix get_current_ts with actuall millisecond resolution than seconds.
Browse files Browse the repository at this point in the history
  • Loading branch information
beyonddream committed Nov 4, 2022
1 parent c0fa103 commit 0a6c4ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"snowid_checkpoint.h": "c",
"unistd.h": "c",
"__locale": "c",
"if_dl.h": "c"
"if_dl.h": "c",
"ctime": "c"
}
}
10 changes: 4 additions & 6 deletions snowid_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>

Expand Down Expand Up @@ -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;
}

0 comments on commit 0a6c4ab

Please sign in to comment.