Updates for Windows WRT timing and condition vars
[yaz-moved-to-github.git] / src / gettimeofday.c
diff --git a/src/gettimeofday.c b/src/gettimeofday.c
new file mode 100644 (file)
index 0000000..c14c36e
--- /dev/null
@@ -0,0 +1,47 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+/**
+ * \file gettimeofday.c
+ * \brief Implements wrapper for gettimeofday
+ *
+ */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef WIN32
+#include <windows.h>
+#include <sys/timeb.h>
+#endif
+#include <time.h>
+#include <yaz/gettimeofday.h>
+
+int yaz_gettimeofday(struct timeval *tval)
+{
+#ifdef WIN32
+    struct _timeb timeb;
+    _ftime(&timeb);
+    tval->tv_sec = timeb.time;
+    tval->tv_usec = timeb.millitm * 1000;
+    return 0;
+#else
+    return gettimeofday(tval, 0);
+#endif
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+