summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2020-08-26 18:44:28 +0000
committerStefan Schmidt <stefan@datenfreihafen.org>2020-08-31 14:24:08 +0200
commitd910fa3fa77860ea2e36c38d0c4b7212d203d159 (patch)
tree2a851349e45d58041f9c63fa21c17b2de4d575f3
parent33304d656cf5a1b4580ce711851c3ebc57f1acea (diff)
Evil: add gettimeofday()
Add gettimeofday implementation based on the mingw one, using a more acurate function if Windows >= 8 Reviewed-by: João Paulo Taylor Ienczak Zanette <joao.tiz@expertisesolutions.com.br> Reviewed-by: Stefan Schmidt <stefan@datenfreihafen.org> Differential Revision: https://phab.enlightenment.org/D12111
-rw-r--r--src/lib/evil/evil_dlfcn.h4
-rw-r--r--src/lib/evil/evil_macro_wrapper.h16
-rw-r--r--src/lib/evil/evil_time.c52
-rw-r--r--src/lib/evil/evil_time.h27
4 files changed, 97 insertions, 2 deletions
diff --git a/src/lib/evil/evil_dlfcn.h b/src/lib/evil/evil_dlfcn.h
index 22f48b72ca..c55ce2562e 100644
--- a/src/lib/evil/evil_dlfcn.h
+++ b/src/lib/evil/evil_dlfcn.h
@@ -194,7 +194,7 @@ EAPI int dlclose(void* handle);
194 */ 194 */
195EAPI void *dlsym(void* handle, const char* symbol); 195EAPI void *dlsym(void* handle, const char* symbol);
196#ifndef HAVE_DLSYM 196#ifndef HAVE_DLSYM
197#define HAVE_DLSYM 1 197# define HAVE_DLSYM 1
198#endif 198#endif
199#ifdef _GNU_SOURCE 199#ifdef _GNU_SOURCE
200 200
@@ -223,7 +223,7 @@ EAPI void *dlsym(void* handle, const char* symbol);
223 */ 223 */
224EAPI int dladdr (const void *addr, Dl_info *info); 224EAPI int dladdr (const void *addr, Dl_info *info);
225#ifndef HAVE_DLADDR 225#ifndef HAVE_DLADDR
226#define HAVE_DLADDR 1 226# define HAVE_DLADDR 1
227#endif 227#endif
228#endif /* _GNU_SOURCE */ 228#endif /* _GNU_SOURCE */
229 229
diff --git a/src/lib/evil/evil_macro_wrapper.h b/src/lib/evil/evil_macro_wrapper.h
index cd650e5e12..640f5a307e 100644
--- a/src/lib/evil/evil_macro_wrapper.h
+++ b/src/lib/evil/evil_macro_wrapper.h
@@ -46,6 +46,22 @@
46#define mkdir(dirname, mode) evil_mkdir(dirname, mode) 46#define mkdir(dirname, mode) evil_mkdir(dirname, mode)
47 47
48/* 48/*
49 * evil_time.h
50 */
51
52/**
53 * @def gettimeofday(tv, tz)
54 *
55 * Wrapper around evil_gettimeofday().
56 *
57 * @since 1.25
58 */
59#ifndef _GETTIMEOFDAY_DEFINED
60# define _GETTIMEOFDAY_DEFINED
61# define gettimeofday(tv, tz) evil_gettimeofday(tv, tz)
62#endif
63
64/*
49 * evil_unistd.h 65 * evil_unistd.h
50 */ 66 */
51 67
diff --git a/src/lib/evil/evil_time.c b/src/lib/evil/evil_time.c
index 32cfc2cf07..7d8de8f37c 100644
--- a/src/lib/evil/evil_time.c
+++ b/src/lib/evil/evil_time.c
@@ -10,6 +10,58 @@
10#include "evil_private.h" 10#include "evil_private.h"
11 11
12/* 12/*
13 * gettimeofday
14 * based on https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-crt/misc/gettimeofday.c
15 * public domain
16 */
17
18#define FILETIME_1970 116444736000000000ull /* seconds between 1/1/1601 and 1/1/1970 */
19
20int evil_gettimeofday(struct timeval *tv, struct timezone *tz)
21{
22 int res = 0;
23 union
24 {
25 unsigned long long ns100; /* time since 1 Jan 1601 in 100ns units */
26 FILETIME ft;
27 } _now;
28 TIME_ZONE_INFORMATION time_zone_information;
29 DWORD tzi;
30
31 if (tz != NULL)
32 {
33 tzi = GetTimeZoneInformation(&time_zone_information);
34 if (tzi != TIME_ZONE_ID_INVALID)
35 {
36 tz->tz_minuteswest = time_zone_information.Bias;
37 if (tzi == TIME_ZONE_ID_DAYLIGHT)
38 tz->tz_dsttime = 1;
39 else
40 tz->tz_dsttime = 0;
41 }
42 else
43 {
44 tz->tz_minuteswest = 0;
45 tz->tz_dsttime = 0;
46 }
47 }
48
49 if (tv != NULL)
50 {
51#if _WIN32_WINNT < 0x0602
52 GetSystemTimeAsFileTime(&_now.ft);
53#else
54 GetSystemTimePreciseAsFileTime(&_now.ft);
55#endif
56 _now.ns100 -= FILETIME_1970; /* 100 nano-seconds since 1-1-1970 */
57 tv->tv_sec = _now.ns100 / 10000000ull; /* seconds since 1-1-1970 */
58 tv->tv_usec = (long) (_now.ns100 % 10000000ull) /10; /* nanoseconds */
59 }
60
61 return res;
62}
63
64/*
13 * strptime 65 * strptime
14 * based on http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/time/strptime.c?rev=HEAD 66 * based on http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/time/strptime.c?rev=HEAD
15 * BSD licence 67 * BSD licence
diff --git a/src/lib/evil/evil_time.h b/src/lib/evil/evil_time.h
index 42004144a2..e61692e079 100644
--- a/src/lib/evil/evil_time.h
+++ b/src/lib/evil/evil_time.h
@@ -16,6 +16,33 @@
16 * @{ 16 * @{
17 */ 17 */
18 18
19#ifdef _MSC_VER
20struct timezone
21{
22 int tz_minuteswest; /* of Greenwich */
23 int tz_dsttime; /* type of dst correction to apply */
24};
25#endif
26
27/**
28 * @brief Get time and timezone.
29 *
30 * @param tv A pointer that contains two sockets.
31 * @param tz A pointer that contains two sockets.
32 * @return 0 on success, -1 otherwise.
33 *
34 * This function gets the time and timezone. @p tv and @p tz can be
35 * @c NULL. It calls GetSystemTimePreciseAsFileTime() on Windows 8or
36 * above if _WIN32_WINNT is correctly defined. It returns 0 on
37 * success, -1 otherwise.
38 *
39 * @since 1.25
40 */
41EAPI int evil_gettimeofday(struct timeval *tv, struct timezone *tz);
42#ifndef HAVE_GETTIMEOFDAY
43# define HAVE_GETTIMEOFDAY 1
44#endif
45
19 46
20/** 47/**
21 * @brief Convert a string representation of time to a time tm structure . 48 * @brief Convert a string representation of time to a time tm structure .