Browse Source

compat: add timespec_get() replacement

pull/35/merge
Rémi Denis-Courmont 11 years ago
parent
commit
383a9210b0
  1. 2
      compat/Makefile.am
  2. 57
      compat/timespec_get.c
  3. 2
      configure.ac
  4. 5
      include/vlc_fixups.h

2
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

57
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;
}

2
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.])
])

5
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;

Loading…
Cancel
Save