diff options
Diffstat (limited to 'src/utils.c')
| -rw-r--r-- | src/utils.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/utils.c b/src/utils.c index 5dd871d..ceb65e1 100644 --- a/src/utils.c +++ b/src/utils.c | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | #include <string.h> | 28 | #include <string.h> |
| 29 | #include <stdio.h> | 29 | #include <stdio.h> |
| 30 | #include <stdarg.h> | 30 | #include <stdarg.h> |
| 31 | #include <time.h> | ||
| 31 | #include <sys/time.h> | 32 | #include <sys/time.h> |
| 32 | 33 | ||
| 33 | #include "utils.h" | 34 | #include "utils.h" |
| @@ -298,15 +299,26 @@ int plist_write_to_filename(plist_t plist, const char *filename, enum plist_form | |||
| 298 | return 1; | 299 | return 1; |
| 299 | } | 300 | } |
| 300 | 301 | ||
| 302 | void get_tick_count(struct timeval * tv) | ||
| 303 | { | ||
| 304 | struct timespec ts; | ||
| 305 | if(0 == clock_gettime(CLOCK_MONOTONIC, &ts)) { | ||
| 306 | tv->tv_sec = ts.tv_sec; | ||
| 307 | tv->tv_usec = ts.tv_nsec / 1000; | ||
| 308 | } else { | ||
| 309 | gettimeofday(tv, NULL); | ||
| 310 | } | ||
| 311 | } | ||
| 312 | |||
| 301 | /** | 313 | /** |
| 302 | * Get number of milliseconds since the epoch. | 314 | * Get number of milliseconds since the epoch. |
| 303 | */ | 315 | */ |
| 304 | uint64_t mstime64(void) | 316 | uint64_t mstime64(void) |
| 305 | { | 317 | { |
| 306 | struct timeval tv; | 318 | struct timeval tv; |
| 307 | gettimeofday(&tv, NULL); | 319 | get_tick_count(&tv); |
| 308 | 320 | ||
| 309 | // Careful, avoid overflow on 32 bit systems | 321 | // Careful, avoid overflow on 32 bit systems |
| 310 | // time_t could be 4 bytes | 322 | // time_t could be 4 bytes |
| 311 | return ((long long)tv.tv_sec) * 1000LL + ((long long)tv.tv_usec) / 1000LL; | 323 | return ((long long)tv.tv_sec) * 1000LL + ((long long)tv.tv_usec) / 1000LL; |
| 312 | } | 324 | } |
