Просмотр исходного кода

compat: Provide a win32 replacement for clock_gettime

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
Hugo Beauzée-Luyssen 9 лет назад
Родитель
Сommit
209f9cc524
1 измененных файлов с 20 добавлено и 0 удалено
  1. 20 0
      compat/clock_gettime.c

+ 20 - 0
compat/clock_gettime.c

@@ -27,6 +27,8 @@
  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef _WIN32
+
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <mach/mach.h>
@@ -57,3 +59,21 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) {
 
     return 0;
 }
+
+#else
+
+#include <windows.h>
+#include <stdint.h>
+#include <time.h>
+
+int clock_gettime(int clk_id, struct timespec *spec) {
+    (void)clk_id;
+    FILETIME wintime;
+    GetSystemTimeAsFileTime(&wintime);
+    uint64_t t = (uint64_t)wintime.dwHighDateTime << 32 | wintime.dwLowDateTime;
+    t -= 116444736000000000;
+    spec->tv_sec  = t / 10000000;
+    spec->tv_nsec = t % 10000000 * 100;
+    return 0;
+}
+#endif