[vlc-commits] compat: add timespec_get() replacement

Rémi Denis-Courmont git at videolan.org
Wed Dec 9 18:18:11 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Dec  9 18:43:22 2015 +0200| [383a9210b05b47315dccc8a5f4592a80f436cd7a] | committer: Rémi Denis-Courmont

compat: add timespec_get() replacement

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=383a9210b05b47315dccc8a5f4592a80f436cd7a
---

 compat/Makefile.am    |    2 +-
 compat/timespec_get.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac          |    2 +-
 include/vlc_fixups.h  |    5 +++++
 4 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/compat/Makefile.am b/compat/Makefile.am
index 8f0c27c..253061d 100644
--- a/compat/Makefile.am
+++ b/compat/Makefile.am
@@ -1,6 +1,6 @@
 pkglib_LTLIBRARIES = libcompat.la
 libcompat_la_SOURCES = dummy.c
-libcompat_la_LIBADD = $(LTLIBOBJS)
+libcompat_la_LIBADD = $(LTLIBOBJS) $(LIBRT)
 libcompat_la_LDFLAGS = -no-undefined -static
 
 BUILT_SOURCES = dummy.c
diff --git a/compat/timespec_get.c b/compat/timespec_get.c
new file mode 100644
index 0000000..63bd454
--- /dev/null
+++ b/compat/timespec_get.c
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * timespec_get.c: C11 timespec_get() replacement
+ *****************************************************************************
+ * Copyright © 2015 Rémi Denis-Courmont
+ *
+ * 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
+
+#include <time.h>
+#include <unistd.h> /* _POSIX_TIMERS */
+#ifndef _POSIX_TIMERS
+#define _POSIX_TIMERS (-1)
+#endif
+
+int timespec_get(struct timespec *ts, int base)
+{
+    switch (base)
+    {
+        case TIME_UTC:
+#if (_POSIX_TIMERS >= 0)
+            if (clock_gettime(CLOCK_REALTIME, ts) == 0)
+                break;
+#endif
+#if (_POSIX_TIMERS <= 0)
+        {
+            struct timeval tv;
+
+            if (gettimeofday(&tv, NULL) == 0)
+            {
+                ts->tv_sec = tv.tv_sec;
+                ts->tv_nsec = tv.tv_usec * 1000;
+                break;
+            }
+        }
+#endif
+            /* fall through */
+        default:
+            return 0;
+    }
+    return base;
+}
diff --git a/configure.ac b/configure.ac
index 9cc640b..9105e2b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -564,7 +564,7 @@ need_libc=false
 dnl Check for usual libc functions
 AC_CHECK_DECLS([nanosleep],,,[#include <time.h>])
 AC_CHECK_FUNCS([daemon fcntl 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 rewind setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy strverscmp])
+AC_REPLACE_FUNCS([atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv nrand48 poll posix_memalign rewind setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy timespec_get strverscmp])
 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 501c0ba..d956c05 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -198,6 +198,11 @@ struct tm *gmtime_r (const time_t *, struct tm *);
 struct tm *localtime_r (const time_t *, struct tm *);
 #endif
 
+#ifndef HAVE_TIMESPEC_GET
+#define TIME_UTC 1
+int timespec_get(struct timespec *, int);
+#endif
+
 /* unistd.h */
 #ifndef HAVE_GETPID
 pid_t getpid (void) VLC_NOTHROW;



More information about the vlc-commits mailing list