time restored

This commit is contained in:
Joao Antonio Cardoso 2020-03-25 14:51:42 -03:00 committed by João Paulo Taylor Ienczak Zanette
parent e499002bdd
commit 66f4e10049
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,28 @@
#include<sys/time.h>
int gettimeofday(struct timeval * tp, struct timezone * tzp)
{
// This number is the number of 100 nanosecond intervals since 00:00:00
// 01/01/1601 (UTC) (Windows way) until 00:00:00 01/01/1970 (POSIX way)
static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
SYSTEMTIME system_time;
FILETIME file_time;
uint64_t time;
GetSystemTime(&system_time);
SystemTimeToFileTime( &system_time, &file_time );
time = ((uint64_t)file_time.dwLowDateTime ) ;
time += ((uint64_t)file_time.dwHighDateTime) << 32;
tp->tv_sec = (long) ((time - EPOCH) / 10000000L);
tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
return 0;
}
struct tm *localtime_r(const time_t * time, struct tm * result)
{
localtime_s(result, time);
return result;
}

View File

@ -0,0 +1,26 @@
#ifndef SYS_TIME_H
#define SYS_TIME_H
#ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
#endif
// Windows Kit for Windows 10 already defines `struct timeval` and `time_t`
#include <winsock2.h>
#include <time.h>
typedef unsigned short u_short;
struct timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of DST correction */
};
typedef long suseconds_t;
typedef struct timeval timeval;
int gettimeofday(struct timeval * tp, struct timezone * tzp);
struct tm *localtime_r(const time_t * time, struct tm * result);
#endif