diff options
author | Darren Tucker <dtucker@zip.com.au> | 2016-03-09 12:46:50 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2016-03-09 12:46:50 +1100 |
commit | 2c48bd344d2c4b5e08dae9aea5ff44fc19a5e363 (patch) | |
tree | 1a23b165057ad8074473697250a36ffcff345019 | |
parent | 7b40ef6c2eef40c339f6ea8920cb8a44838e10c9 (diff) |
Add compat to monotime_double().
Apply all of the portability changes in monotime() to monotime() double.
Fixes build on at least older FreeBSD systems.
-rw-r--r-- | misc.c | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -912,12 +912,26 @@ monotime(void) | |||
912 | double | 912 | double |
913 | monotime_double(void) | 913 | monotime_double(void) |
914 | { | 914 | { |
915 | #if defined(HAVE_CLOCK_GETTIME) && \ | ||
916 | (defined(CLOCK_MONOTONIC) || defined(CLOCK_BOOTTIME)) | ||
915 | struct timespec ts; | 917 | struct timespec ts; |
918 | static int gettime_failed = 0; | ||
916 | 919 | ||
917 | if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) | 920 | if (!gettime_failed) { |
918 | fatal("clock_gettime: %s", strerror(errno)); | 921 | #if defined(CLOCK_BOOTTIME) |
922 | if (clock_gettime(CLOCK_BOOTTIME, &ts) == 0) | ||
923 | return (ts.tv_sec + (double)ts.tv_nsec / 1000000000); | ||
924 | #endif | ||
925 | #if defined(CLOCK_MONOTONIC) | ||
926 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) | ||
927 | return (ts.tv_sec + (double)ts.tv_nsec / 1000000000); | ||
928 | #endif | ||
929 | debug3("clock_gettime: %s", strerror(errno)); | ||
930 | gettime_failed = 1; | ||
931 | } | ||
932 | #endif /* HAVE_CLOCK_GETTIME && (CLOCK_MONOTONIC || CLOCK_BOOTTIME */ | ||
919 | 933 | ||
920 | return (ts.tv_sec + (double)ts.tv_nsec / 1000000000); | 934 | return (double)time(NULL); |
921 | } | 935 | } |
922 | 936 | ||
923 | void | 937 | void |