[vlc-devel] [PATCH] compat: Provide a gettimeofday replacement

Steve Lhomme robux4 at gmail.com
Mon Feb 1 09:52:53 CET 2016


On Sat, Jan 30, 2016 at 3:44 PM, Rémi Denis-Courmont <remi at remlab.net> wrote:
> Le 2016-01-30 10:26, Steve Lhomme a écrit :
>>
>> From: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
>
>
> Possibly correct, but I don't really see the point since gettimeofday() is
> only used on POSIX, OS/2 and MacOS, where it is always found.

It's used by timespec_get() when _POSIX_TIMERS is not defined. We
could make a Windows version of timespec_get() but to get the extra
precision there isn't much available before Windows 8 (which
introduces GetSystemTimePreciseAsFileTime).


>>
>> ---
>>  compat/gettimeofday.c | 53
>> +++++++++++++++++++++++++++++++++++++++++++++++++++
>>  configure.ac          |  1 +
>>  include/vlc_fixups.h  | 13 +++++++++++++
>>  3 files changed, 67 insertions(+)
>>  create mode 100644 compat/gettimeofday.c
>>
>> diff --git a/compat/gettimeofday.c b/compat/gettimeofday.c
>> new file mode 100644
>> index 0000000..cbe68d1
>> --- /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 34b0080..95f5f9c 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -575,6 +575,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;
>
>
> --
> Rémi Denis-Courmont
> http://www.remlab.net/
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list