summaryrefslogtreecommitdiff
path: root/source/kit/time.h
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-12-29 06:21:33 +0100
committerMitya Selivanov <automainint@guattari.tech>2023-12-29 06:21:33 +0100
commit2d6c8fec45b23a8a28668ecf3ef281139ab778a7 (patch)
tree75d2a8538992129a83c0c2b83688289443d697e5 /source/kit/time.h
parent820b171245f2f14766f3accdb0246a4e2c0d596a (diff)
downloadsaw-2d6c8fec45b23a8a28668ecf3ef281139ab778a7.zip
refactor dependencies; include dependencies source code
Diffstat (limited to 'source/kit/time.h')
-rw-r--r--source/kit/time.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/source/kit/time.h b/source/kit/time.h
new file mode 100644
index 0000000..c14f8ff
--- /dev/null
+++ b/source/kit/time.h
@@ -0,0 +1,54 @@
+#ifndef KIT_TIME_H
+#define KIT_TIME_H
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
+#include <time.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef TIME_UTC
+# define TIME_UTC 1
+#endif
+
+#ifdef KIT_REQUIRE_TIMESPEC_GET
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN 1
+# endif
+# ifndef NOMINMAX
+# define NOMINMAX 1
+# endif
+# include <windows.h>
+
+# define KIT_TIMESPEC_IMPL_UNIX_EPOCH_IN_TICKS 116444736000000000ull
+# define KIT_TIMESPEC_IMPL_TICKS_PER_SECONDS 10000000ull
+
+static int timespec_get(struct timespec *ts, int base) {
+ if (ts == NULL || base != TIME_UTC)
+ return 0;
+
+ FILETIME ft;
+ ULARGE_INTEGER date;
+ LONGLONG ticks;
+
+ GetSystemTimeAsFileTime(&ft);
+ date.HighPart = ft.dwHighDateTime;
+ date.LowPart = ft.dwLowDateTime;
+ ticks = (LONGLONG) (date.QuadPart -
+ KIT_TIMESPEC_IMPL_UNIX_EPOCH_IN_TICKS);
+ ts->tv_sec = ticks / KIT_TIMESPEC_IMPL_TICKS_PER_SECONDS;
+ ts->tv_nsec = (ticks % KIT_TIMESPEC_IMPL_TICKS_PER_SECONDS) * 100;
+
+ return base;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif