summaryrefslogtreecommitdiffstats
path: root/src/xtime.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-11-07 13:04:11 -0500
committerTavian Barnes <tavianator@tavianator.com>2022-11-07 13:04:11 -0500
commit3139cbc56a08ac76bccfe223dd2669f3f080c927 (patch)
tree0276d073a6494a50382c5a86f2434691190705bf /src/xtime.c
parentddfe02342f89703e723699238a424396204aa1cf (diff)
downloadbfs-3139cbc56a08ac76bccfe223dd2669f3f080c927.tar.xz
xtime: Move parse_gettime() to xgettime()
Diffstat (limited to 'src/xtime.c')
-rw-r--r--src/xtime.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/xtime.c b/src/xtime.c
index bcd4e66..153b267 100644
--- a/src/xtime.c
+++ b/src/xtime.c
@@ -19,7 +19,9 @@
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <sys/time.h>
#include <time.h>
+#include <unistd.h>
/** Whether tzset() has been called. */
static bool tz_is_set = false;
@@ -321,3 +323,17 @@ invalid:
error:
return -1;
}
+
+int xgettime(struct timespec *result) {
+#if _POSIX_TIMERS > 0
+ return clock_gettime(CLOCK_REALTIME, result);
+#else
+ struct timeval tv;
+ int ret = gettimeofday(&tv, NULL);
+ if (ret == 0) {
+ result->tv_sec = tv.tv_sec;
+ result->tv_nsec = tv.tv_usec * 1000L;
+ }
+ return ret;
+#endif
+}