lwip/contrib/ports/win32/check/time.c

67 lines
1.3 KiB
C
Raw Permalink Normal View History

#include <time.h>
#include <windows.h>
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif
#include "config.h"
2018-10-22 18:33:35 +00:00
struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
2018-10-22 18:33:35 +00:00
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag;
2018-10-22 18:33:35 +00:00
if (NULL != tv) {
GetSystemTimeAsFileTime(&ft);
2018-10-22 18:33:35 +00:00
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
2018-10-22 18:33:35 +00:00
/*converting file time to unix epoch*/
2018-10-22 18:33:35 +00:00
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tmpres /= 10; /*convert into microseconds*/
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}
2018-10-22 18:33:35 +00:00
if (NULL != tz) {
if (!tzflag) {
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
2018-10-22 18:33:35 +00:00
return 0;
}
struct tm *
localtime_r(const time_t *timer, struct tm *result)
{
struct tm *local_result;
if (result == NULL) {
return NULL;
}
local_result = localtime (timer);
if (local_result == NULL) {
return NULL;
}
memcpy(result, local_result, sizeof(*result));
return result;
}