[vlc-commits] compat: Provide a gettimeofday replacement
Hugo Beauzée-Luyssen
git at videolan.org
Sat Feb 6 11:48:10 CET 2016
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Sat Jan 30 09:26:29 2016 +0100| [d9c923331233f74ceca658d3e9b4ef6d3d295f97] | committer: Jean-Baptiste Kempf
compat: Provide a gettimeofday replacement
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d9c923331233f74ceca658d3e9b4ef6d3d295f97
---
compat/gettimeofday.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 1 +
include/vlc_fixups.h | 13 ++++++++++++
3 files changed, 67 insertions(+)
diff --git a/compat/gettimeofday.c b/compat/gettimeofday.c
new file mode 100644
index 0000000..9e95534
--- /dev/null
+++ b/compat/gettimeofday.c
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * gettimeofday.c: gettimeofday() replacement
+ *****************************************************************************
+ * Copyright © 2014 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef _WIN32
+#include <winsock2.h>
+
+/* FILETIME of Jan 1 1970 00:00:00. */
+static const unsigned __int64 epoch = 116444736000000000;
+
+/*
+ * timezone information is stored outside the kernel so tzp isn't used anymore.
+ *
+ * Note: this function is not for Win32 high precision timing purpose. See
+ * elapsed_time().
+ */
+int gettimeofday(struct timeval * tp, struct timezone * tzp)
+{
+ FILETIME file_time;
+ SYSTEMTIME system_time;
+ ULARGE_INTEGER ularge;
+
+ GetSystemTime(&system_time);
+ SystemTimeToFileTime(&system_time, &file_time);
+ ularge.LowPart = file_time.dwLowDateTime;
+ ularge.HighPart = file_time.dwHighDateTime;
+
+ tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L);
+ tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
+
+ return 0;
+}
+#endif /* _WIN32 */
diff --git a/configure.ac b/configure.ac
index 7605cf7..3e9eb21 100644
--- a/configure.ac
+++ b/configure.ac
@@ -576,6 +576,7 @@ dnl Check for usual libc functions
AC_CHECK_DECLS([nanosleep],,,[#include <time.h>])
AC_CHECK_FUNCS([daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap open_memstream openat pread posix_fadvise posix_madvise setlocale stricmp strnicmp strptime uselocale pthread_cond_timedwait_monotonic_np pthread_condattr_setclock])
AC_REPLACE_FUNCS([atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv nrand48 poll posix_memalign recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy timegm timespec_get strverscmp])
+AC_REPLACE_FUNCS([gettimeofday])
AC_CHECK_FUNCS(fdatasync,,
[AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
])
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index ed2781c..4bfed0f 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -45,6 +45,14 @@
# include <time.h> /* time_t */
#endif
+#ifndef HAVE_GETTIMEOFDAY
+#ifdef _WIN32
+#include <winsock2.h>
+#else
+#include <sys/time.h>
+#endif
+#endif
+
#ifndef HAVE_LLDIV
typedef struct
{
@@ -209,6 +217,11 @@ struct timespec;
int timespec_get(struct timespec *, int);
#endif
+/* sys/time.h */
+#ifndef HAVE_GETTIMEOFDAY
+int gettimeofday(struct timeval *, struct timezone *);
+#endif
+
/* unistd.h */
#ifndef HAVE_GETPID
pid_t getpid (void) VLC_NOTHROW;
More information about the vlc-commits
mailing list