2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll date/time functions
|
|
|
|
*
|
|
|
|
* Copyright 1996,1998 Marcus Meissner
|
|
|
|
* Copyright 1996 Jukka Iivonen
|
|
|
|
* Copyright 1997,2000 Uwe Bonnes
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2004-03-19 02:16:59 +01:00
|
|
|
* Copyright 2004 Hans Leidekker
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library 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 library 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 library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-23 20:22:33 +02:00
|
|
|
|
2002-08-26 23:53:24 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-12-10 12:46:46 +01:00
|
|
|
#include <stdlib.h>
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2001-04-23 20:22:33 +02:00
|
|
|
#include "msvcrt.h"
|
2010-03-29 00:01:53 +02:00
|
|
|
#include "mtdll.h"
|
2004-03-11 01:43:47 +01:00
|
|
|
#include "winbase.h"
|
2006-07-10 11:54:10 +02:00
|
|
|
#include "winnls.h"
|
2011-07-28 01:42:53 +02:00
|
|
|
#include "winternl.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2018-12-21 12:44:39 +01:00
|
|
|
BOOL WINAPI GetDaylightFlag(void);
|
|
|
|
|
2019-10-16 13:20:58 +02:00
|
|
|
static LONGLONG init_time;
|
|
|
|
|
|
|
|
void msvcrt_init_clock(void)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER systime;
|
|
|
|
|
|
|
|
NtQuerySystemTime(&systime);
|
|
|
|
init_time = systime.QuadPart;
|
|
|
|
}
|
|
|
|
|
2004-03-19 02:16:59 +01:00
|
|
|
static const int MonthLengths[2][12] =
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2004-03-19 02:16:59 +01:00
|
|
|
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
|
|
|
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
|
|
|
};
|
|
|
|
|
2019-11-22 01:28:07 +01:00
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
static const int MAX_SECONDS = 60;
|
|
|
|
#else
|
|
|
|
static const int MAX_SECONDS = 59;
|
|
|
|
#endif
|
|
|
|
|
2013-10-10 21:52:44 +02:00
|
|
|
static inline BOOL IsLeapYear(int Year)
|
2004-03-19 02:16:59 +01:00
|
|
|
{
|
|
|
|
return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2010-10-11 12:24:20 +02:00
|
|
|
static inline void write_invalid_msvcrt_tm( struct MSVCRT_tm *tm )
|
|
|
|
{
|
|
|
|
tm->tm_sec = -1;
|
|
|
|
tm->tm_min = -1;
|
|
|
|
tm->tm_hour = -1;
|
|
|
|
tm->tm_mday = -1;
|
|
|
|
tm->tm_mon = -1;
|
|
|
|
tm->tm_year = -1;
|
|
|
|
tm->tm_wday = -1;
|
|
|
|
tm->tm_yday = -1;
|
|
|
|
tm->tm_isdst = -1;
|
|
|
|
}
|
|
|
|
|
2012-12-10 12:46:46 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _daylight (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int MSVCRT___daylight = 1;
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _timezone (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_long MSVCRT___timezone = 28800;
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _dstbias (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int MSVCRT__dstbias = -3600;
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _tzname (MSVCRT.@)
|
|
|
|
* NOTES
|
|
|
|
* Some apps (notably Mozilla) insist on writing to these, so the buffer
|
|
|
|
* must be large enough.
|
|
|
|
*/
|
|
|
|
static char tzname_std[64] = "PST";
|
|
|
|
static char tzname_dst[64] = "PDT";
|
|
|
|
char *MSVCRT__tzname[2] = { tzname_std, tzname_dst };
|
|
|
|
|
|
|
|
static TIME_ZONE_INFORMATION tzi = {0};
|
|
|
|
/*********************************************************************
|
|
|
|
* _tzset (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void CDECL MSVCRT__tzset(void)
|
|
|
|
{
|
|
|
|
char *tz = MSVCRT_getenv("TZ");
|
|
|
|
BOOL error;
|
|
|
|
|
|
|
|
_mlock(_TIME_LOCK);
|
|
|
|
if(tz && tz[0]) {
|
|
|
|
BOOL neg_zone = FALSE;
|
|
|
|
|
|
|
|
memset(&tzi, 0, sizeof(tzi));
|
|
|
|
|
|
|
|
/* Parse timezone information: tzn[+|-]hh[:mm[:ss]][dzn] */
|
|
|
|
lstrcpynA(MSVCRT__tzname[0], tz, 3);
|
|
|
|
tz += 3;
|
|
|
|
|
|
|
|
if(*tz == '-') {
|
|
|
|
neg_zone = TRUE;
|
|
|
|
tz++;
|
|
|
|
}else if(*tz == '+') {
|
|
|
|
tz++;
|
|
|
|
}
|
|
|
|
MSVCRT___timezone = strtol(tz, &tz, 10)*3600;
|
|
|
|
if(*tz == ':') {
|
|
|
|
MSVCRT___timezone += strtol(tz+1, &tz, 10)*60;
|
|
|
|
if(*tz == ':')
|
|
|
|
MSVCRT___timezone += strtol(tz+1, &tz, 10);
|
|
|
|
}
|
|
|
|
if(neg_zone)
|
|
|
|
MSVCRT___timezone = -MSVCRT___timezone;
|
|
|
|
|
|
|
|
MSVCRT___daylight = *tz;
|
|
|
|
lstrcpynA(MSVCRT__tzname[1], tz, 3);
|
|
|
|
}else if(GetTimeZoneInformation(&tzi) != TIME_ZONE_ID_INVALID) {
|
|
|
|
MSVCRT___timezone = tzi.Bias*60;
|
|
|
|
if(tzi.StandardDate.wMonth)
|
|
|
|
MSVCRT___timezone += tzi.StandardBias*60;
|
|
|
|
|
|
|
|
if(tzi.DaylightDate.wMonth) {
|
|
|
|
MSVCRT___daylight = 1;
|
|
|
|
MSVCRT__dstbias = (tzi.DaylightBias-tzi.StandardBias)*60;
|
|
|
|
}else {
|
|
|
|
MSVCRT___daylight = 0;
|
|
|
|
MSVCRT__dstbias = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!WideCharToMultiByte(CP_ACP, 0, tzi.StandardName, -1, MSVCRT__tzname[0],
|
|
|
|
sizeof(tzname_std), NULL, &error) || error)
|
|
|
|
*MSVCRT__tzname[0] = 0;
|
|
|
|
if(!WideCharToMultiByte(CP_ACP, 0, tzi.DaylightName, -1, MSVCRT__tzname[1],
|
|
|
|
sizeof(tzname_dst), NULL, &error) || error)
|
|
|
|
*MSVCRT__tzname[0] = 0;
|
|
|
|
}
|
|
|
|
_munlock(_TIME_LOCK);
|
|
|
|
}
|
|
|
|
|
2012-12-10 12:47:13 +01:00
|
|
|
static void _tzset_init(void)
|
|
|
|
{
|
|
|
|
static BOOL init = FALSE;
|
|
|
|
|
|
|
|
if(!init) {
|
|
|
|
_mlock(_TIME_LOCK);
|
|
|
|
if(!init) {
|
|
|
|
MSVCRT__tzset();
|
|
|
|
init = TRUE;
|
|
|
|
}
|
|
|
|
_munlock(_TIME_LOCK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL is_dst(const SYSTEMTIME *st)
|
|
|
|
{
|
|
|
|
TIME_ZONE_INFORMATION tmp;
|
|
|
|
SYSTEMTIME out;
|
|
|
|
|
|
|
|
if(!MSVCRT___daylight)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if(tzi.DaylightDate.wMonth) {
|
|
|
|
tmp = tzi;
|
|
|
|
}else if(st->wYear >= 2007) {
|
|
|
|
memset(&tmp, 0, sizeof(tmp));
|
|
|
|
tmp.StandardDate.wMonth = 11;
|
|
|
|
tmp.StandardDate.wDay = 1;
|
|
|
|
tmp.StandardDate.wHour = 2;
|
|
|
|
tmp.DaylightDate.wMonth = 3;
|
|
|
|
tmp.DaylightDate.wDay = 2;
|
|
|
|
tmp.DaylightDate.wHour = 2;
|
|
|
|
}else {
|
|
|
|
memset(&tmp, 0, sizeof(tmp));
|
|
|
|
tmp.StandardDate.wMonth = 10;
|
|
|
|
tmp.StandardDate.wDay = 5;
|
|
|
|
tmp.StandardDate.wHour = 2;
|
|
|
|
tmp.DaylightDate.wMonth = 4;
|
|
|
|
tmp.DaylightDate.wDay = 1;
|
|
|
|
tmp.DaylightDate.wHour = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp.Bias = 0;
|
|
|
|
tmp.StandardBias = 0;
|
|
|
|
tmp.DaylightBias = MSVCRT__dstbias/60;
|
|
|
|
if(!SystemTimeToTzSpecificLocalTime(&tmp, st, &out))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return memcmp(st, &out, sizeof(SYSTEMTIME));
|
|
|
|
}
|
|
|
|
|
2004-03-19 02:16:59 +01:00
|
|
|
#define SECSPERDAY 86400
|
|
|
|
/* 1601 to 1970 is 369 years plus 89 leap days */
|
|
|
|
#define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
|
|
|
|
#define TICKSPERSEC 10000000
|
|
|
|
#define TICKSPERMSEC 10000
|
|
|
|
#define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
|
|
|
|
|
2012-12-10 12:47:13 +01:00
|
|
|
static MSVCRT___time64_t mktime_helper(struct MSVCRT_tm *mstm, BOOL local)
|
|
|
|
{
|
|
|
|
SYSTEMTIME st;
|
|
|
|
FILETIME ft;
|
|
|
|
MSVCRT___time64_t ret = 0;
|
|
|
|
int i;
|
|
|
|
BOOL use_dst = FALSE;
|
|
|
|
|
|
|
|
ret = mstm->tm_year + mstm->tm_mon/12;
|
|
|
|
mstm->tm_mon %= 12;
|
|
|
|
if(mstm->tm_mon < 0) {
|
|
|
|
mstm->tm_mon += 12;
|
|
|
|
ret--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret<70 || ret>1100) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&st, 0, sizeof(SYSTEMTIME));
|
|
|
|
st.wDay = 1;
|
|
|
|
st.wMonth = mstm->tm_mon+1;
|
|
|
|
st.wYear = ret+1900;
|
|
|
|
|
|
|
|
if(!SystemTimeToFileTime(&st, &ft)) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ((MSVCRT___time64_t)ft.dwHighDateTime<<32)+ft.dwLowDateTime;
|
|
|
|
ret += (MSVCRT___time64_t)mstm->tm_sec*TICKSPERSEC;
|
|
|
|
ret += (MSVCRT___time64_t)mstm->tm_min*60*TICKSPERSEC;
|
|
|
|
ret += (MSVCRT___time64_t)mstm->tm_hour*60*60*TICKSPERSEC;
|
|
|
|
ret += (MSVCRT___time64_t)(mstm->tm_mday-1)*SECSPERDAY*TICKSPERSEC;
|
|
|
|
|
|
|
|
ft.dwLowDateTime = ret & 0xffffffff;
|
|
|
|
ft.dwHighDateTime = ret >> 32;
|
|
|
|
FileTimeToSystemTime(&ft, &st);
|
|
|
|
|
|
|
|
if(local) {
|
|
|
|
_tzset_init();
|
|
|
|
use_dst = is_dst(&st);
|
|
|
|
if((mstm->tm_isdst<=-1 && use_dst) || (mstm->tm_isdst>=1)) {
|
|
|
|
SYSTEMTIME tmp;
|
|
|
|
|
|
|
|
ret += (MSVCRT___time64_t)MSVCRT__dstbias*TICKSPERSEC;
|
|
|
|
|
|
|
|
ft.dwLowDateTime = ret & 0xffffffff;
|
|
|
|
ft.dwHighDateTime = ret >> 32;
|
|
|
|
FileTimeToSystemTime(&ft, &tmp);
|
|
|
|
|
|
|
|
if(!is_dst(&tmp)) {
|
|
|
|
st = tmp;
|
|
|
|
use_dst = FALSE;
|
|
|
|
}else {
|
|
|
|
use_dst = TRUE;
|
|
|
|
}
|
|
|
|
}else if(mstm->tm_isdst==0 && use_dst) {
|
|
|
|
ret -= (MSVCRT___time64_t)MSVCRT__dstbias*TICKSPERSEC;
|
|
|
|
ft.dwLowDateTime = ret & 0xffffffff;
|
|
|
|
ft.dwHighDateTime = ret >> 32;
|
|
|
|
FileTimeToSystemTime(&ft, &st);
|
|
|
|
ret += (MSVCRT___time64_t)MSVCRT__dstbias*TICKSPERSEC;
|
|
|
|
}
|
|
|
|
ret += (MSVCRT___time64_t)MSVCRT___timezone*TICKSPERSEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
mstm->tm_sec = st.wSecond;
|
|
|
|
mstm->tm_min = st.wMinute;
|
|
|
|
mstm->tm_hour = st.wHour;
|
|
|
|
mstm->tm_mday = st.wDay;
|
|
|
|
mstm->tm_mon = st.wMonth-1;
|
|
|
|
mstm->tm_year = st.wYear-1900;
|
|
|
|
mstm->tm_wday = st.wDayOfWeek;
|
|
|
|
for(i=mstm->tm_yday=0; i<st.wMonth-1; i++)
|
|
|
|
mstm->tm_yday += MonthLengths[IsLeapYear(st.wYear)][i];
|
|
|
|
mstm->tm_yday += st.wDay-1;
|
|
|
|
mstm->tm_isdst = use_dst ? 1 : 0;
|
|
|
|
|
|
|
|
if(ret < TICKS_1601_TO_1970) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ret = (ret-TICKS_1601_TO_1970)/TICKSPERSEC;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-11-12 16:47:26 +01:00
|
|
|
/**********************************************************************
|
2009-05-23 11:06:29 +02:00
|
|
|
* _mktime64 (MSVCRT.@)
|
2001-11-12 16:47:26 +01:00
|
|
|
*/
|
2009-05-23 11:06:29 +02:00
|
|
|
MSVCRT___time64_t CDECL MSVCRT__mktime64(struct MSVCRT_tm *mstm)
|
2001-11-12 16:47:26 +01:00
|
|
|
{
|
2012-12-10 12:47:13 +01:00
|
|
|
return mktime_helper(mstm, TRUE);
|
2004-03-19 02:16:59 +01:00
|
|
|
}
|
|
|
|
|
2009-05-23 11:06:29 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* _mktime32 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT___time32_t CDECL MSVCRT__mktime32(struct MSVCRT_tm *mstm)
|
|
|
|
{
|
2012-12-10 12:47:13 +01:00
|
|
|
MSVCRT___time64_t ret = MSVCRT__mktime64( mstm );
|
|
|
|
return ret == (MSVCRT___time32_t)ret ? ret : -1;
|
2009-05-23 11:06:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* mktime (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
#ifdef _WIN64
|
|
|
|
MSVCRT___time64_t CDECL MSVCRT_mktime(struct MSVCRT_tm *mstm)
|
|
|
|
{
|
|
|
|
return MSVCRT__mktime64( mstm );
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
MSVCRT___time32_t CDECL MSVCRT_mktime(struct MSVCRT_tm *mstm)
|
|
|
|
{
|
|
|
|
return MSVCRT__mktime32( mstm );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-27 08:42:13 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* _mkgmtime64 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* time->tm_isdst value is ignored
|
|
|
|
*/
|
|
|
|
MSVCRT___time64_t CDECL MSVCRT__mkgmtime64(struct MSVCRT_tm *time)
|
|
|
|
{
|
2012-12-10 12:47:26 +01:00
|
|
|
return mktime_helper(time, FALSE);
|
2010-04-27 08:42:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* _mkgmtime32 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT___time32_t CDECL MSVCRT__mkgmtime32(struct MSVCRT_tm *time)
|
|
|
|
{
|
2012-12-10 12:47:26 +01:00
|
|
|
MSVCRT___time64_t ret = MSVCRT__mkgmtime64(time);
|
|
|
|
return ret == (MSVCRT___time32_t)ret ? ret : -1;
|
2010-04-27 08:42:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* _mkgmtime (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
#ifdef _WIN64
|
|
|
|
MSVCRT___time64_t CDECL MSVCRT__mkgmtime(struct MSVCRT_tm *time)
|
|
|
|
{
|
|
|
|
return MSVCRT__mkgmtime64(time);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
MSVCRT___time32_t CDECL MSVCRT__mkgmtime(struct MSVCRT_tm *time)
|
|
|
|
{
|
|
|
|
return MSVCRT__mkgmtime32(time);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-10-11 12:24:20 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _localtime64_s (MSVCRT.@)
|
|
|
|
*/
|
2012-12-10 12:48:07 +01:00
|
|
|
int CDECL _localtime64_s(struct MSVCRT_tm *res, const MSVCRT___time64_t *secs)
|
2010-10-11 12:24:20 +02:00
|
|
|
{
|
2012-12-10 12:48:07 +01:00
|
|
|
int i;
|
|
|
|
FILETIME ft;
|
|
|
|
SYSTEMTIME st;
|
|
|
|
ULONGLONG time;
|
2010-10-11 12:24:20 +02:00
|
|
|
|
2012-12-10 12:48:07 +01:00
|
|
|
if (!res || !secs || *secs < 0 || *secs > _MAX__TIME64_T)
|
2010-10-11 12:24:20 +02:00
|
|
|
{
|
2012-12-10 12:48:07 +01:00
|
|
|
if (res)
|
|
|
|
write_invalid_msvcrt_tm(res);
|
2010-10-11 12:24:20 +02:00
|
|
|
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-12-10 12:48:07 +01:00
|
|
|
_tzset_init();
|
|
|
|
time = (*secs - MSVCRT___timezone) * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
|
2010-10-11 12:24:20 +02:00
|
|
|
|
2012-12-10 12:48:07 +01:00
|
|
|
ft.dwHighDateTime = (UINT)(time >> 32);
|
|
|
|
ft.dwLowDateTime = (UINT)time;
|
|
|
|
FileTimeToSystemTime(&ft, &st);
|
|
|
|
|
|
|
|
res->tm_isdst = is_dst(&st) ? 1 : 0;
|
|
|
|
if(res->tm_isdst) {
|
|
|
|
time -= MSVCRT__dstbias * (ULONGLONG)TICKSPERSEC;
|
|
|
|
ft.dwHighDateTime = (UINT)(time >> 32);
|
|
|
|
ft.dwLowDateTime = (UINT)time;
|
|
|
|
FileTimeToSystemTime(&ft, &st);
|
2010-10-11 12:24:20 +02:00
|
|
|
}
|
|
|
|
|
2012-12-10 12:48:07 +01:00
|
|
|
res->tm_sec = st.wSecond;
|
|
|
|
res->tm_min = st.wMinute;
|
|
|
|
res->tm_hour = st.wHour;
|
|
|
|
res->tm_mday = st.wDay;
|
|
|
|
res->tm_year = st.wYear - 1900;
|
|
|
|
res->tm_mon = st.wMonth - 1;
|
|
|
|
res->tm_wday = st.wDayOfWeek;
|
|
|
|
for (i = res->tm_yday = 0; i < st.wMonth - 1; i++)
|
|
|
|
res->tm_yday += MonthLengths[IsLeapYear(st.wYear)][i];
|
|
|
|
res->tm_yday += st.wDay - 1;
|
|
|
|
|
2010-10-11 12:24:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-10 12:47:54 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _localtime64 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
struct MSVCRT_tm* CDECL MSVCRT__localtime64(const MSVCRT___time64_t* secs)
|
|
|
|
{
|
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
|
|
|
|
if(!data->time_buffer)
|
|
|
|
data->time_buffer = MSVCRT_malloc(sizeof(struct MSVCRT_tm));
|
|
|
|
|
|
|
|
if(_localtime64_s(data->time_buffer, secs))
|
|
|
|
return NULL;
|
|
|
|
return data->time_buffer;
|
|
|
|
}
|
|
|
|
|
2005-12-21 20:54:26 +01:00
|
|
|
/*********************************************************************
|
2009-05-23 11:06:29 +02:00
|
|
|
* _localtime32 (MSVCRT.@)
|
2005-12-21 20:54:26 +01:00
|
|
|
*/
|
2009-05-23 11:06:29 +02:00
|
|
|
struct MSVCRT_tm* CDECL MSVCRT__localtime32(const MSVCRT___time32_t* secs)
|
|
|
|
{
|
2012-12-10 12:47:54 +01:00
|
|
|
MSVCRT___time64_t secs64;
|
|
|
|
|
|
|
|
if(!secs)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
secs64 = *secs;
|
2009-05-23 11:06:29 +02:00
|
|
|
return MSVCRT__localtime64( &secs64 );
|
|
|
|
}
|
|
|
|
|
2010-10-11 12:25:05 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _localtime32_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _localtime32_s(struct MSVCRT_tm *time, const MSVCRT___time32_t *secs)
|
|
|
|
{
|
|
|
|
MSVCRT___time64_t secs64;
|
|
|
|
|
|
|
|
if (!time || !secs || *secs < 0)
|
|
|
|
{
|
|
|
|
if (time)
|
|
|
|
write_invalid_msvcrt_tm(time);
|
|
|
|
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
secs64 = *secs;
|
|
|
|
return _localtime64_s(time, &secs64);
|
|
|
|
}
|
|
|
|
|
2009-05-23 11:06:29 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* localtime (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
#ifdef _WIN64
|
|
|
|
struct MSVCRT_tm* CDECL MSVCRT_localtime(const MSVCRT___time64_t* secs)
|
|
|
|
{
|
|
|
|
return MSVCRT__localtime64( secs );
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
struct MSVCRT_tm* CDECL MSVCRT_localtime(const MSVCRT___time32_t* secs)
|
|
|
|
{
|
|
|
|
return MSVCRT__localtime32( secs );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _gmtime64 (MSVCRT.@)
|
|
|
|
*/
|
2010-08-27 01:46:09 +02:00
|
|
|
int CDECL MSVCRT__gmtime64_s(struct MSVCRT_tm *res, const MSVCRT___time64_t *secs)
|
2004-03-19 02:16:59 +01:00
|
|
|
{
|
2010-08-27 01:46:09 +02:00
|
|
|
int i;
|
|
|
|
FILETIME ft;
|
|
|
|
SYSTEMTIME st;
|
|
|
|
ULONGLONG time;
|
|
|
|
|
2012-12-10 12:47:40 +01:00
|
|
|
if (!res || !secs || *secs < 0 || *secs > _MAX__TIME64_T) {
|
2010-10-11 12:24:30 +02:00
|
|
|
if (res) {
|
|
|
|
write_invalid_msvcrt_tm(res);
|
2010-08-27 01:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
2004-03-19 02:16:59 +01:00
|
|
|
|
2010-08-27 01:46:09 +02:00
|
|
|
time = *secs * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
|
2004-03-19 02:16:59 +01:00
|
|
|
|
2010-08-27 01:46:09 +02:00
|
|
|
ft.dwHighDateTime = (UINT)(time >> 32);
|
|
|
|
ft.dwLowDateTime = (UINT)time;
|
2004-03-19 02:16:59 +01:00
|
|
|
|
2010-08-27 01:46:09 +02:00
|
|
|
FileTimeToSystemTime(&ft, &st);
|
2004-03-19 02:16:59 +01:00
|
|
|
|
2010-08-27 01:46:09 +02:00
|
|
|
res->tm_sec = st.wSecond;
|
|
|
|
res->tm_min = st.wMinute;
|
|
|
|
res->tm_hour = st.wHour;
|
|
|
|
res->tm_mday = st.wDay;
|
|
|
|
res->tm_year = st.wYear - 1900;
|
|
|
|
res->tm_mon = st.wMonth - 1;
|
|
|
|
res->tm_wday = st.wDayOfWeek;
|
|
|
|
for (i = res->tm_yday = 0; i < st.wMonth - 1; i++) {
|
|
|
|
res->tm_yday += MonthLengths[IsLeapYear(st.wYear)][i];
|
|
|
|
}
|
2004-03-19 02:16:59 +01:00
|
|
|
|
2010-08-27 01:46:09 +02:00
|
|
|
res->tm_yday += st.wDay - 1;
|
|
|
|
res->tm_isdst = 0;
|
2004-03-19 02:16:59 +01:00
|
|
|
|
2010-08-27 01:46:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2004-03-19 02:16:59 +01:00
|
|
|
|
2010-08-27 01:46:09 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _gmtime64 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
struct MSVCRT_tm* CDECL MSVCRT__gmtime64(const MSVCRT___time64_t *secs)
|
|
|
|
{
|
|
|
|
thread_data_t * const data = msvcrt_get_thread_data();
|
|
|
|
|
2011-05-24 17:22:54 +02:00
|
|
|
if(!data->time_buffer)
|
|
|
|
data->time_buffer = MSVCRT_malloc(sizeof(struct MSVCRT_tm));
|
|
|
|
|
|
|
|
if(MSVCRT__gmtime64_s(data->time_buffer, secs))
|
2010-08-27 01:46:09 +02:00
|
|
|
return NULL;
|
2011-05-24 17:22:54 +02:00
|
|
|
return data->time_buffer;
|
2010-08-27 01:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _gmtime32_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__gmtime32_s(struct MSVCRT_tm *res, const MSVCRT___time32_t *secs)
|
|
|
|
{
|
|
|
|
MSVCRT___time64_t secs64;
|
|
|
|
|
|
|
|
if(secs) {
|
|
|
|
secs64 = *secs;
|
|
|
|
return MSVCRT__gmtime64_s(res, &secs64);
|
|
|
|
}
|
|
|
|
return MSVCRT__gmtime64_s(res, NULL);
|
2001-11-12 16:47:26 +01:00
|
|
|
}
|
|
|
|
|
2009-05-23 11:06:29 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _gmtime32 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
struct MSVCRT_tm* CDECL MSVCRT__gmtime32(const MSVCRT___time32_t* secs)
|
|
|
|
{
|
2010-08-27 01:46:09 +02:00
|
|
|
MSVCRT___time64_t secs64;
|
|
|
|
|
|
|
|
if(!secs)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
secs64 = *secs;
|
2009-05-23 11:06:29 +02:00
|
|
|
return MSVCRT__gmtime64( &secs64 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* gmtime (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
#ifdef _WIN64
|
|
|
|
struct MSVCRT_tm* CDECL MSVCRT_gmtime(const MSVCRT___time64_t* secs)
|
|
|
|
{
|
|
|
|
return MSVCRT__gmtime64( secs );
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
struct MSVCRT_tm* CDECL MSVCRT_gmtime(const MSVCRT___time32_t* secs)
|
|
|
|
{
|
|
|
|
return MSVCRT__gmtime32( secs );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* _strdate (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
char* CDECL MSVCRT__strdate(char* date)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-21 07:25:28 +02:00
|
|
|
static const char format[] = "MM'/'dd'/'yy";
|
2004-03-19 02:16:59 +01:00
|
|
|
|
|
|
|
GetDateFormatA(LOCALE_NEUTRAL, 0, NULL, format, date, 9);
|
|
|
|
|
|
|
|
return date;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2010-08-27 01:46:00 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* _strdate_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _strdate_s(char* date, MSVCRT_size_t size)
|
|
|
|
{
|
|
|
|
if(date && size)
|
|
|
|
date[0] = '\0';
|
|
|
|
|
|
|
|
if(!date) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(size < 9) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT__strdate(date);
|
2010-08-27 01:46:00 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-30 20:03:58 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* _wstrdate (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT_wchar_t* CDECL MSVCRT__wstrdate(MSVCRT_wchar_t* date)
|
2005-10-30 20:03:58 +01:00
|
|
|
{
|
|
|
|
static const WCHAR format[] = { 'M','M','\'','/','\'','d','d','\'','/','\'','y','y',0 };
|
|
|
|
|
2009-01-29 11:15:54 +01:00
|
|
|
GetDateFormatW(LOCALE_NEUTRAL, 0, NULL, format, date, 9);
|
2005-10-30 20:03:58 +01:00
|
|
|
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
2010-08-27 01:46:00 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* _wstrdate_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _wstrdate_s(MSVCRT_wchar_t* date, MSVCRT_size_t size)
|
|
|
|
{
|
|
|
|
if(date && size)
|
|
|
|
date[0] = '\0';
|
|
|
|
|
|
|
|
if(!date) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(size < 9) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT__wstrdate(date);
|
2010-08-27 01:46:00 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _strtime (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
char* CDECL MSVCRT__strtime(char* time)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-21 07:25:28 +02:00
|
|
|
static const char format[] = "HH':'mm':'ss";
|
2004-03-19 02:16:59 +01:00
|
|
|
|
2005-10-30 20:03:58 +01:00
|
|
|
GetTimeFormatA(LOCALE_NEUTRAL, 0, NULL, format, time, 9);
|
2004-03-19 02:16:59 +01:00
|
|
|
|
2005-10-30 20:03:58 +01:00
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2010-08-27 01:45:31 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _strtime_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _strtime_s(char* time, MSVCRT_size_t size)
|
|
|
|
{
|
|
|
|
if(time && size)
|
|
|
|
time[0] = '\0';
|
|
|
|
|
|
|
|
if(!time) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(size < 9) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT__strtime(time);
|
2010-08-27 01:45:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-30 20:03:58 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wstrtime (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT_wchar_t* CDECL MSVCRT__wstrtime(MSVCRT_wchar_t* time)
|
2005-10-30 20:03:58 +01:00
|
|
|
{
|
|
|
|
static const WCHAR format[] = { 'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0 };
|
|
|
|
|
2009-01-29 11:15:54 +01:00
|
|
|
GetTimeFormatW(LOCALE_NEUTRAL, 0, NULL, format, time, 9);
|
2005-10-30 20:03:58 +01:00
|
|
|
|
|
|
|
return time;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2010-08-27 01:45:31 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wstrtime_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _wstrtime_s(MSVCRT_wchar_t* time, MSVCRT_size_t size)
|
|
|
|
{
|
|
|
|
if(time && size)
|
|
|
|
time[0] = '\0';
|
|
|
|
|
|
|
|
if(!time) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(size < 9) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT__wstrtime(time);
|
2010-08-27 01:45:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* clock (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_clock_t CDECL MSVCRT_clock(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-07-28 01:42:53 +02:00
|
|
|
LARGE_INTEGER systime;
|
2004-03-19 02:16:59 +01:00
|
|
|
|
2011-07-28 01:42:53 +02:00
|
|
|
NtQuerySystemTime(&systime);
|
2019-10-16 13:20:58 +02:00
|
|
|
return (systime.QuadPart - init_time) / (TICKSPERSEC / MSVCRT_CLOCKS_PER_SEC);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2009-05-23 11:06:29 +02:00
|
|
|
* _difftime64 (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2009-05-23 11:06:29 +02:00
|
|
|
double CDECL MSVCRT__difftime64(MSVCRT___time64_t time1, MSVCRT___time64_t time2)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2004-03-19 02:16:59 +01:00
|
|
|
return (double)(time1 - time2);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2009-05-23 11:06:29 +02:00
|
|
|
* _difftime32 (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2009-05-23 11:06:29 +02:00
|
|
|
double CDECL MSVCRT__difftime32(MSVCRT___time32_t time1, MSVCRT___time32_t time2)
|
|
|
|
{
|
|
|
|
return (double)(time1 - time2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* difftime (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
#ifdef _WIN64
|
|
|
|
double CDECL MSVCRT_difftime(MSVCRT___time64_t time1, MSVCRT___time64_t time2)
|
|
|
|
{
|
|
|
|
return MSVCRT__difftime64( time1, time2 );
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
double CDECL MSVCRT_difftime(MSVCRT___time32_t time1, MSVCRT___time32_t time2)
|
|
|
|
{
|
|
|
|
return MSVCRT__difftime32( time1, time2 );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ftime64 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void CDECL MSVCRT__ftime64(struct MSVCRT___timeb64 *buf)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2004-03-11 01:43:47 +01:00
|
|
|
FILETIME ft;
|
|
|
|
ULONGLONG time;
|
|
|
|
|
2018-12-21 12:44:26 +01:00
|
|
|
_tzset_init();
|
|
|
|
|
2004-03-11 01:43:47 +01:00
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
|
|
|
|
time = ((ULONGLONG)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
|
|
|
|
|
|
|
|
buf->time = time / TICKSPERSEC - SECS_1601_TO_1970;
|
|
|
|
buf->millitm = (time % TICKSPERSEC) / TICKSPERMSEC;
|
2018-12-21 12:44:26 +01:00
|
|
|
buf->timezone = MSVCRT___timezone / 60;
|
2018-12-21 12:44:39 +01:00
|
|
|
buf->dstflag = GetDaylightFlag();
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2003-03-04 03:19:15 +01:00
|
|
|
|
2010-12-28 14:24:04 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ftime64_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__ftime64_s(struct MSVCRT___timeb64 *buf)
|
|
|
|
{
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT( buf != NULL )) return MSVCRT_EINVAL;
|
2010-12-28 14:24:04 +01:00
|
|
|
MSVCRT__ftime64(buf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-25 03:19:15 +02:00
|
|
|
/*********************************************************************
|
2009-05-23 11:06:29 +02:00
|
|
|
* _ftime32 (MSVCRT.@)
|
2004-06-25 03:19:15 +02:00
|
|
|
*/
|
2009-05-23 11:06:29 +02:00
|
|
|
void CDECL MSVCRT__ftime32(struct MSVCRT___timeb32 *buf)
|
2004-06-25 03:19:15 +02:00
|
|
|
{
|
2009-05-23 11:06:29 +02:00
|
|
|
struct MSVCRT___timeb64 buf64;
|
2004-06-25 03:19:15 +02:00
|
|
|
|
2009-05-23 11:06:29 +02:00
|
|
|
MSVCRT__ftime64( &buf64 );
|
|
|
|
buf->time = buf64.time;
|
|
|
|
buf->millitm = buf64.millitm;
|
|
|
|
buf->timezone = buf64.timezone;
|
|
|
|
buf->dstflag = buf64.dstflag;
|
|
|
|
}
|
2004-06-25 03:19:15 +02:00
|
|
|
|
2010-12-28 14:24:04 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ftime32_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__ftime32_s(struct MSVCRT___timeb32 *buf)
|
|
|
|
{
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT( buf != NULL )) return MSVCRT_EINVAL;
|
2010-12-28 14:24:04 +01:00
|
|
|
MSVCRT__ftime32(buf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-23 11:06:29 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _ftime (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
#ifdef _WIN64
|
|
|
|
void CDECL MSVCRT__ftime(struct MSVCRT___timeb64 *buf)
|
|
|
|
{
|
2011-08-06 13:51:16 +02:00
|
|
|
MSVCRT__ftime64( buf );
|
2004-06-25 03:19:15 +02:00
|
|
|
}
|
2009-05-23 11:06:29 +02:00
|
|
|
#else
|
|
|
|
void CDECL MSVCRT__ftime(struct MSVCRT___timeb32 *buf)
|
|
|
|
{
|
2011-08-06 13:51:16 +02:00
|
|
|
MSVCRT__ftime32( buf );
|
2009-05-23 11:06:29 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _time64 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT___time64_t CDECL MSVCRT__time64(MSVCRT___time64_t *buf)
|
|
|
|
{
|
|
|
|
MSVCRT___time64_t curtime;
|
|
|
|
struct MSVCRT___timeb64 tb;
|
|
|
|
|
|
|
|
MSVCRT__ftime64(&tb);
|
|
|
|
|
|
|
|
curtime = tb.time;
|
|
|
|
return buf ? *buf = curtime : curtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _time32 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT___time32_t CDECL MSVCRT__time32(MSVCRT___time32_t *buf)
|
|
|
|
{
|
|
|
|
MSVCRT___time32_t curtime;
|
|
|
|
struct MSVCRT___timeb64 tb;
|
|
|
|
|
|
|
|
MSVCRT__ftime64(&tb);
|
|
|
|
|
|
|
|
curtime = tb.time;
|
|
|
|
return buf ? *buf = curtime : curtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* time (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
#ifdef _WIN64
|
|
|
|
MSVCRT___time64_t CDECL MSVCRT_time(MSVCRT___time64_t* buf)
|
|
|
|
{
|
|
|
|
return MSVCRT__time64( buf );
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
MSVCRT___time32_t CDECL MSVCRT_time(MSVCRT___time32_t* buf)
|
|
|
|
{
|
|
|
|
return MSVCRT__time32( buf );
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-25 03:19:15 +02:00
|
|
|
|
2003-03-04 03:19:15 +01:00
|
|
|
/*********************************************************************
|
2014-09-10 19:39:17 +02:00
|
|
|
* __p__daylight (MSVCRT.@)
|
2003-03-04 03:19:15 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int * CDECL MSVCRT___p__daylight(void)
|
2003-03-04 03:19:15 +01:00
|
|
|
{
|
|
|
|
return &MSVCRT___daylight;
|
|
|
|
}
|
2005-04-23 21:06:29 +02:00
|
|
|
|
2005-09-27 12:55:50 +02:00
|
|
|
/*********************************************************************
|
2014-09-10 19:39:17 +02:00
|
|
|
* __p__dstbias (MSVCRT.@)
|
2005-09-27 12:55:50 +02:00
|
|
|
*/
|
2014-09-10 19:39:17 +02:00
|
|
|
int * CDECL MSVCRT___p__dstbias(void)
|
2005-09-27 12:55:50 +02:00
|
|
|
{
|
|
|
|
return &MSVCRT__dstbias;
|
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:02 +01:00
|
|
|
#if _MSVCR_VER >= 80
|
2017-02-28 18:23:38 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _get_dstbias (MSVCR80.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__get_dstbias(int *seconds)
|
|
|
|
{
|
|
|
|
if (!MSVCRT_CHECK_PMT(seconds != NULL)) return MSVCRT_EINVAL;
|
|
|
|
*seconds = MSVCRT__dstbias;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-01-04 05:33:02 +01:00
|
|
|
#endif
|
2017-02-28 18:23:38 +01:00
|
|
|
|
2005-05-14 13:07:10 +02:00
|
|
|
/*********************************************************************
|
2014-09-10 19:39:17 +02:00
|
|
|
* __p__timezone (MSVCRT.@)
|
2005-05-14 13:07:10 +02:00
|
|
|
*/
|
2009-05-23 11:49:09 +02:00
|
|
|
MSVCRT_long * CDECL MSVCRT___p__timezone(void)
|
2005-05-14 13:07:10 +02:00
|
|
|
{
|
|
|
|
return &MSVCRT___timezone;
|
|
|
|
}
|
|
|
|
|
2010-11-03 02:12:28 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _get_tzname (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__get_tzname(MSVCRT_size_t *ret, char *buf, MSVCRT_size_t bufsize, int index)
|
|
|
|
{
|
|
|
|
char *timezone;
|
|
|
|
|
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
timezone = tzname_std;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
timezone = tzname_dst;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ret || (!buf && bufsize > 0) || (buf && !bufsize))
|
|
|
|
{
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = strlen(timezone)+1;
|
|
|
|
if(!buf && !bufsize)
|
|
|
|
return 0;
|
2019-02-27 18:37:10 +01:00
|
|
|
if(*ret > bufsize)
|
|
|
|
{
|
|
|
|
buf[0] = 0;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
2010-11-03 02:12:28 +01:00
|
|
|
|
|
|
|
strcpy(buf, timezone);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-23 21:06:29 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __p_tzname (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
char ** CDECL __p__tzname(void)
|
2005-04-23 21:06:29 +02:00
|
|
|
{
|
|
|
|
return MSVCRT__tzname;
|
|
|
|
}
|
2005-05-14 13:07:10 +02:00
|
|
|
|
2019-11-19 23:14:42 +01:00
|
|
|
#if _MSVCR_VER <= 90
|
|
|
|
#define STRFTIME_CHAR char
|
|
|
|
#define STRFTIME_TD(td, name) td->str.names.name
|
|
|
|
#else
|
|
|
|
#define STRFTIME_CHAR MSVCRT_wchar_t
|
|
|
|
#define STRFTIME_TD(td, name) td->wstr.names.name
|
|
|
|
#endif
|
|
|
|
|
2019-11-19 23:15:01 +01:00
|
|
|
#define strftime_str(a,b,c,d) strftime_nstr(a,b,c,d,MSVCRT_SIZE_MAX)
|
|
|
|
static inline BOOL strftime_nstr(STRFTIME_CHAR *str, MSVCRT_size_t *pos,
|
|
|
|
MSVCRT_size_t max, const STRFTIME_CHAR *src, MSVCRT_size_t len)
|
2019-11-13 22:07:42 +01:00
|
|
|
{
|
2019-11-19 23:15:01 +01:00
|
|
|
while(*src && len)
|
2019-11-19 23:14:42 +01:00
|
|
|
{
|
|
|
|
if(*pos >= max) {
|
|
|
|
*str = 0;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-11-13 22:07:42 +01:00
|
|
|
|
2019-11-19 23:14:42 +01:00
|
|
|
str[*pos] = *src;
|
|
|
|
src++;
|
|
|
|
*pos += 1;
|
2019-11-19 23:15:01 +01:00
|
|
|
len--;
|
2012-04-11 15:22:25 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:14:42 +01:00
|
|
|
static inline BOOL strftime_int(STRFTIME_CHAR *str, MSVCRT_size_t *pos, MSVCRT_size_t max,
|
2012-04-11 15:22:25 +02:00
|
|
|
int src, int prec, int l, int h)
|
|
|
|
{
|
2019-11-19 23:14:42 +01:00
|
|
|
#if _MSVCR_VER > 90
|
|
|
|
static const WCHAR fmt[] = {'%','0','*','d',0};
|
|
|
|
#endif
|
2012-04-11 15:22:25 +02:00
|
|
|
MSVCRT_size_t len;
|
|
|
|
|
2019-11-25 15:10:05 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(src>=l && src<=h)) {
|
2012-04-11 15:22:25 +02:00
|
|
|
*str = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:14:42 +01:00
|
|
|
#if _MSVCR_VER <= 90
|
2012-04-11 15:22:25 +02:00
|
|
|
len = MSVCRT__snprintf(str+*pos, max-*pos, "%0*d", prec, src);
|
2019-11-19 23:14:42 +01:00
|
|
|
#else
|
|
|
|
len = MSVCRT__snwprintf(str+*pos, max-*pos, fmt, prec, src);
|
|
|
|
#endif
|
2012-04-11 15:22:25 +02:00
|
|
|
if(len == -1) {
|
|
|
|
*str = 0;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pos += len;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:15:01 +01:00
|
|
|
static inline BOOL strftime_format(STRFTIME_CHAR *str, MSVCRT_size_t *pos, MSVCRT_size_t max,
|
|
|
|
const struct MSVCRT_tm *mstm, MSVCRT___lc_time_data *time_data, const STRFTIME_CHAR *format)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t count;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
while(*format && ret)
|
|
|
|
{
|
|
|
|
count = 1;
|
|
|
|
while(format[0] == format[count]) count++;
|
|
|
|
|
|
|
|
switch(*format) {
|
|
|
|
case '\'':
|
|
|
|
if(count % 2 == 0) break;
|
|
|
|
|
|
|
|
format += count;
|
|
|
|
count = 0;
|
|
|
|
while(format[count] && format[count] != '\'') count++;
|
|
|
|
|
|
|
|
ret = strftime_nstr(str, pos, max, format, count);
|
|
|
|
if(!ret) return FALSE;
|
|
|
|
if(format[count] == '\'') count++;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2019-11-21 14:04:21 +01:00
|
|
|
if(count > 2)
|
|
|
|
{
|
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
|
|
|
|
{
|
|
|
|
*str = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2019-11-19 23:15:01 +01:00
|
|
|
switch(count) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2019-11-22 01:28:08 +01:00
|
|
|
ret = strftime_int(str, pos, max, mstm->tm_mday, count==1 ? 0 : 2, 1, 31);
|
2019-11-19 23:15:01 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ret = strftime_str(str, pos, max, STRFTIME_TD(time_data, short_wday)[mstm->tm_wday]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = strftime_nstr(str, pos, max, format, count-4);
|
|
|
|
if(ret)
|
|
|
|
ret = strftime_str(str, pos, max, STRFTIME_TD(time_data, wday)[mstm->tm_wday]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'M':
|
2019-11-21 14:04:21 +01:00
|
|
|
if(count > 2)
|
|
|
|
{
|
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_mon>=0 && mstm->tm_mon<=11))
|
|
|
|
{
|
|
|
|
*str = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2019-11-19 23:15:01 +01:00
|
|
|
switch(count) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
ret = strftime_int(str, pos, max, mstm->tm_mon+1, count==1 ? 0 : 2, 1, 12);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ret = strftime_str(str, pos, max, STRFTIME_TD(time_data, short_mon)[mstm->tm_mon]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = strftime_nstr(str, pos, max, format, count-4);
|
|
|
|
if(ret)
|
|
|
|
ret = strftime_str(str, pos, max, STRFTIME_TD(time_data, mon)[mstm->tm_mon]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
if(count > 1)
|
|
|
|
{
|
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_year >= -1900 && mstm->tm_year <= 8099))
|
|
|
|
#else
|
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_year >= 0))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
*str = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(count) {
|
|
|
|
case 1:
|
|
|
|
ret = strftime_nstr(str, pos, max, format, 1);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
ret = strftime_nstr(str, pos, max, format, count-2);
|
|
|
|
if(ret)
|
|
|
|
ret = strftime_int(str, pos, max, (mstm->tm_year+1900)%100, 2, 0, 99);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = strftime_nstr(str, pos, max, format, count-4);
|
|
|
|
if(ret)
|
|
|
|
ret = strftime_int(str, pos, max, mstm->tm_year+1900, 4, 0, 9999);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2019-11-21 14:04:22 +01:00
|
|
|
case 'h':
|
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
|
|
|
|
{
|
|
|
|
*str = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(count > 2)
|
|
|
|
ret = strftime_nstr(str, pos, max, format, count-2);
|
|
|
|
if(ret)
|
|
|
|
ret = strftime_int(str, pos, max, (mstm->tm_hour + 11) % 12 + 1,
|
|
|
|
count == 1 ? 0 : 2, 1, 12);
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
if(count > 2)
|
|
|
|
ret = strftime_nstr(str, pos, max, format, count-2);
|
|
|
|
if(ret)
|
|
|
|
ret = strftime_int(str, pos, max, mstm->tm_hour, count == 1 ? 0 : 2, 0, 23);
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if(count > 2)
|
|
|
|
ret = strftime_nstr(str, pos, max, format, count-2);
|
|
|
|
if(ret)
|
|
|
|
ret = strftime_int(str, pos, max, mstm->tm_min, count == 1 ? 0 : 2, 0, 59);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if(count > 2)
|
|
|
|
ret = strftime_nstr(str, pos, max, format, count-2);
|
|
|
|
if(ret)
|
2019-11-22 01:28:07 +01:00
|
|
|
ret = strftime_int(str, pos, max, mstm->tm_sec, count == 1 ? 0 : 2, 0, MAX_SECONDS);
|
2019-11-21 14:04:22 +01:00
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
case 'A':
|
|
|
|
case 't':
|
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
|
|
|
|
{
|
|
|
|
*str = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ret = strftime_nstr(str, pos, max,
|
|
|
|
mstm->tm_hour < 12 ? STRFTIME_TD(time_data, am) : STRFTIME_TD(time_data, pm),
|
|
|
|
(*format == 't' && count == 1) ? 1 : MSVCRT_SIZE_MAX);
|
|
|
|
break;
|
2019-11-19 23:15:01 +01:00
|
|
|
default:
|
|
|
|
ret = strftime_nstr(str, pos, max, format, count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
format += count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-11-26 17:49:19 +01:00
|
|
|
#if _MSVCR_VER>=140
|
2019-11-19 23:14:42 +01:00
|
|
|
static inline BOOL strftime_tzdiff(STRFTIME_CHAR *str, MSVCRT_size_t *pos, MSVCRT_size_t max, BOOL is_dst)
|
|
|
|
{
|
|
|
|
MSVCRT_long tz = MSVCRT___timezone + (is_dst ? MSVCRT__dstbias : 0);
|
|
|
|
char sign;
|
|
|
|
|
|
|
|
if(tz < 0) {
|
|
|
|
sign = '+';
|
|
|
|
tz = -tz;
|
|
|
|
}else {
|
|
|
|
sign = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*pos < max)
|
|
|
|
str[(*pos)++] = sign;
|
|
|
|
if(!strftime_int(str, pos, max, tz/60/60, 2, 0, 99))
|
|
|
|
return FALSE;
|
|
|
|
return strftime_int(str, pos, max, tz/60%60, 2, 0, 59);
|
|
|
|
}
|
2019-11-26 17:49:19 +01:00
|
|
|
#endif
|
2019-11-19 23:14:42 +01:00
|
|
|
|
|
|
|
static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
|
|
|
|
const STRFTIME_CHAR *format, const struct MSVCRT_tm *mstm,
|
|
|
|
MSVCRT___lc_time_data *time_data, MSVCRT__locale_t loc)
|
2012-04-11 15:22:25 +02:00
|
|
|
{
|
|
|
|
MSVCRT_size_t ret, tmp;
|
|
|
|
BOOL alternate;
|
2019-11-22 01:28:06 +01:00
|
|
|
int year = mstm ? mstm->tm_year + 1900 : -1;
|
2012-04-11 15:22:25 +02:00
|
|
|
|
|
|
|
if(!str || !format) {
|
|
|
|
if(str && max)
|
|
|
|
*str = 0;
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!time_data)
|
2016-08-10 17:18:09 +02:00
|
|
|
time_data = loc ? loc->locinfo->lc_time_curr : get_locinfo()->lc_time_curr;
|
2012-04-11 15:22:25 +02:00
|
|
|
|
|
|
|
for(ret=0; *format && ret<max; format++) {
|
|
|
|
if(*format != '%') {
|
2016-08-10 17:18:09 +02:00
|
|
|
if(MSVCRT__isleadbyte_l((unsigned char)*format, loc)) {
|
2016-08-10 17:18:05 +02:00
|
|
|
str[ret++] = *(format++);
|
|
|
|
if(ret == max) continue;
|
2019-11-13 22:07:57 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(str[ret]))
|
|
|
|
goto einval_error;
|
2016-08-10 17:18:05 +02:00
|
|
|
}
|
2012-04-11 15:22:25 +02:00
|
|
|
str[ret++] = *format;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
format++;
|
|
|
|
if(*format == '#') {
|
|
|
|
alternate = TRUE;
|
|
|
|
format++;
|
|
|
|
}else {
|
|
|
|
alternate = FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-13 22:07:57 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(mstm))
|
2012-04-11 15:22:25 +02:00
|
|
|
goto einval_error;
|
|
|
|
|
|
|
|
switch(*format) {
|
|
|
|
case 'c':
|
2019-12-04 15:30:57 +01:00
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
if(time_data == &cloc_time_data && !alternate)
|
|
|
|
{
|
|
|
|
static const WCHAR datetime_format[] =
|
|
|
|
{ '%','a',' ','%','b',' ','%','e',' ','%','T',' ','%','Y',0 };
|
|
|
|
tmp = strftime_impl(str+ret, max-ret, datetime_format, mstm, time_data, loc);
|
|
|
|
if(!tmp)
|
|
|
|
return 0;
|
|
|
|
ret += tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2019-11-19 23:15:01 +01:00
|
|
|
if(!strftime_format(str, &ret, max, mstm, time_data,
|
|
|
|
alternate ? STRFTIME_TD(time_data, date) : STRFTIME_TD(time_data, short_date)))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = ' ';
|
2019-11-21 14:04:22 +01:00
|
|
|
if(!strftime_format(str, &ret, max, mstm, time_data, STRFTIME_TD(time_data, time)))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'x':
|
2019-11-19 23:15:01 +01:00
|
|
|
if(!strftime_format(str, &ret, max, mstm, time_data,
|
|
|
|
alternate ? STRFTIME_TD(time_data, date) : STRFTIME_TD(time_data, short_date)))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'X':
|
2019-11-21 14:04:22 +01:00
|
|
|
if(!strftime_format(str, &ret, max, mstm, time_data, STRFTIME_TD(time_data, time)))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'a':
|
2019-11-13 22:07:57 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
|
2012-04-11 15:22:25 +02:00
|
|
|
goto einval_error;
|
2019-11-19 23:14:42 +01:00
|
|
|
if(!strftime_str(str, &ret, max, STRFTIME_TD(time_data, short_wday)[mstm->tm_wday]))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'A':
|
2019-11-13 22:07:57 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
|
2012-04-11 15:22:25 +02:00
|
|
|
goto einval_error;
|
2019-11-19 23:14:42 +01:00
|
|
|
if(!strftime_str(str, &ret, max, STRFTIME_TD(time_data, wday)[mstm->tm_wday]))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'b':
|
2019-10-04 19:53:20 +02:00
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
case 'h':
|
|
|
|
#endif
|
2019-11-13 22:07:57 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_mon>=0 && mstm->tm_mon<=11))
|
2012-04-11 15:22:25 +02:00
|
|
|
goto einval_error;
|
2019-11-19 23:14:42 +01:00
|
|
|
if(!strftime_str(str, &ret, max, STRFTIME_TD(time_data, short_mon)[mstm->tm_mon]))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'B':
|
2019-11-13 22:07:57 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_mon>=0 && mstm->tm_mon<=11))
|
2012-04-11 15:22:25 +02:00
|
|
|
goto einval_error;
|
2019-11-19 23:14:42 +01:00
|
|
|
if(!strftime_str(str, &ret, max, STRFTIME_TD(time_data, mon)[mstm->tm_mon]))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
2019-10-02 22:11:38 +02:00
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
case 'C':
|
2019-11-22 01:28:06 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
|
|
|
|
goto einval_error;
|
|
|
|
if(!strftime_int(str, &ret, max, year/100, alternate ? 0 : 2, 0, 99))
|
2019-10-02 22:11:38 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
#endif
|
2012-04-11 15:22:25 +02:00
|
|
|
case 'd':
|
2019-11-22 01:28:08 +01:00
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 1, 31))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
2019-10-01 11:51:07 +02:00
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
case 'D':
|
2019-11-22 01:28:06 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
|
|
|
|
goto einval_error;
|
2019-10-01 11:51:07 +02:00
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_mon+1, alternate ? 0 : 2, 1, 12))
|
|
|
|
return 0;
|
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = '/';
|
2019-11-22 01:28:08 +01:00
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 1, 31))
|
2019-10-01 11:51:07 +02:00
|
|
|
return 0;
|
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = '/';
|
2019-11-22 01:28:06 +01:00
|
|
|
if(!strftime_int(str, &ret, max, year%100, alternate ? 0 : 2, 0, 99))
|
2019-10-01 11:51:07 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
2019-10-03 16:27:33 +02:00
|
|
|
case 'e':
|
2019-11-22 01:28:08 +01:00
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 1, 31))
|
2019-10-03 16:27:33 +02:00
|
|
|
return 0;
|
|
|
|
if(!alternate && str[ret-2] == '0')
|
|
|
|
str[ret-2] = ' ';
|
|
|
|
break;
|
2019-10-01 11:51:08 +02:00
|
|
|
case 'F':
|
2019-11-22 01:28:06 +01:00
|
|
|
if(!strftime_int(str, &ret, max, year, alternate ? 0 : 4, 0, 9999))
|
2019-10-01 11:51:08 +02:00
|
|
|
return 0;
|
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = '-';
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_mon+1, alternate ? 0 : 2, 1, 12))
|
|
|
|
return 0;
|
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = '-';
|
2019-11-22 01:28:08 +01:00
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 1, 31))
|
2019-10-01 11:51:08 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
2019-10-29 14:43:52 +01:00
|
|
|
case 'g':
|
2019-10-28 13:28:54 +01:00
|
|
|
case 'G':
|
2019-11-27 17:52:25 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
|
|
|
|
goto einval_error;
|
2019-11-27 17:52:37 +01:00
|
|
|
/* fall through */
|
2019-11-27 17:52:31 +01:00
|
|
|
case 'V':
|
|
|
|
{
|
|
|
|
int iso_year = year;
|
|
|
|
int iso_days = mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4;
|
|
|
|
if (iso_days < 0)
|
|
|
|
iso_days += 365 + IsLeapYear(--iso_year);
|
|
|
|
else if(iso_days >= 365 + IsLeapYear(iso_year))
|
|
|
|
iso_days -= 365 + IsLeapYear(iso_year++);
|
|
|
|
|
2019-11-27 17:52:37 +01:00
|
|
|
if(*format == 'G') {
|
|
|
|
if(!strftime_int(str, &ret, max, iso_year, 4, 0, 9999))
|
|
|
|
return 0;
|
|
|
|
} else if(*format == 'g') {
|
|
|
|
if(!strftime_int(str, &ret, max, iso_year%100, 2, 0, 99))
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
if(!strftime_int(str, &ret, max, iso_days/7 + 1, alternate ? 0 : 2, 0, 53))
|
|
|
|
return 0;
|
|
|
|
}
|
2019-11-27 17:52:31 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-10-01 11:51:07 +02:00
|
|
|
#endif
|
2012-04-11 15:22:25 +02:00
|
|
|
case 'H':
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'I':
|
2019-11-22 01:28:09 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
|
|
|
|
goto einval_error;
|
|
|
|
if(!strftime_int(str, &ret, max, (mstm->tm_hour + 11) % 12 + 1,
|
|
|
|
alternate ? 0 : 2, 1, 12))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_yday+1, alternate ? 0 : 3, 1, 366))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_mon+1, alternate ? 0 : 2, 1, 12))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59))
|
|
|
|
return 0;
|
|
|
|
break;
|
2019-10-11 22:35:23 +02:00
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
case 'n':
|
|
|
|
str[ret++] = '\n';
|
|
|
|
break;
|
|
|
|
#endif
|
2012-04-11 15:22:25 +02:00
|
|
|
case 'p':
|
2019-11-13 22:07:57 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
|
2012-04-11 15:22:25 +02:00
|
|
|
goto einval_error;
|
|
|
|
if(!strftime_str(str, &ret, max, mstm->tm_hour<12 ?
|
2019-11-19 23:14:42 +01:00
|
|
|
STRFTIME_TD(time_data, am) : STRFTIME_TD(time_data, pm)))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
2019-09-30 16:52:14 +02:00
|
|
|
#if _MSVCR_VER>=140
|
2019-11-28 08:57:42 +01:00
|
|
|
case 'r':
|
2019-12-04 15:30:57 +01:00
|
|
|
if(time_data == &cloc_time_data)
|
2019-11-28 08:57:42 +01:00
|
|
|
{
|
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
|
|
|
|
goto einval_error;
|
|
|
|
if(!strftime_int(str, &ret, max, (mstm->tm_hour + 11) % 12 + 1,
|
|
|
|
alternate ? 0 : 2, 1, 12))
|
|
|
|
return 0;
|
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = ':';
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59))
|
|
|
|
return 0;
|
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = ':';
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_sec, alternate ? 0 : 2, 0, MAX_SECONDS))
|
|
|
|
return 0;
|
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = ' ';
|
|
|
|
if(!strftime_str(str, &ret, max, mstm->tm_hour<12 ?
|
|
|
|
STRFTIME_TD(time_data, am) : STRFTIME_TD(time_data, pm)))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!strftime_format(str, &ret, max, mstm, time_data, STRFTIME_TD(time_data, time)))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2019-09-30 16:52:14 +02:00
|
|
|
case 'R':
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23))
|
|
|
|
return 0;
|
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = ':';
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
#endif
|
2012-04-11 15:22:25 +02:00
|
|
|
case 'S':
|
2019-11-22 01:28:07 +01:00
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_sec, alternate ? 0 : 2, 0, MAX_SECONDS))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
2019-09-27 16:28:26 +02:00
|
|
|
#if _MSVCR_VER>=140
|
2019-10-11 22:35:23 +02:00
|
|
|
case 't':
|
|
|
|
str[ret++] = '\t';
|
|
|
|
break;
|
2019-09-27 16:28:26 +02:00
|
|
|
case 'T':
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23))
|
|
|
|
return 0;
|
2019-09-30 16:52:07 +02:00
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = ':';
|
2019-09-27 16:28:26 +02:00
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59))
|
|
|
|
return 0;
|
2019-09-30 16:52:07 +02:00
|
|
|
if(ret < max)
|
|
|
|
str[ret++] = ':';
|
2019-11-22 01:28:07 +01:00
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_sec, alternate ? 0 : 2, 0, MAX_SECONDS))
|
2019-09-27 16:28:26 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
2019-10-18 11:58:59 +02:00
|
|
|
case 'u':
|
2019-11-22 01:28:10 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
|
|
|
|
goto einval_error;
|
2019-10-18 11:58:59 +02:00
|
|
|
tmp = mstm->tm_wday ? mstm->tm_wday : 7;
|
|
|
|
if(!strftime_int(str, &ret, max, tmp, 0, 1, 7))
|
|
|
|
return 0;
|
|
|
|
break;
|
2019-09-27 16:28:26 +02:00
|
|
|
#endif
|
2012-04-11 15:22:25 +02:00
|
|
|
case 'w':
|
|
|
|
if(!strftime_int(str, &ret, max, mstm->tm_wday, 0, 0, 6))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'y':
|
2019-11-13 22:08:03 +01:00
|
|
|
#if _MSVCR_VER>=140
|
2019-11-22 01:28:06 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
|
2019-11-13 22:08:03 +01:00
|
|
|
#else
|
2019-11-22 01:28:06 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(year>=1900))
|
2019-11-13 22:08:03 +01:00
|
|
|
#endif
|
2019-11-22 01:28:06 +01:00
|
|
|
goto einval_error;
|
|
|
|
if(!strftime_int(str, &ret, max, year%100, alternate ? 0 : 2, 0, 99))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'Y':
|
2019-11-22 01:28:06 +01:00
|
|
|
if(!strftime_int(str, &ret, max, year, alternate ? 0 : 4, 0, 9999))
|
2012-04-11 15:22:25 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'z':
|
2019-11-13 22:07:42 +01:00
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
MSVCRT__tzset();
|
|
|
|
if(!strftime_tzdiff(str, &ret, max, mstm->tm_isdst))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
#endif
|
2012-04-11 15:22:25 +02:00
|
|
|
case 'Z':
|
|
|
|
MSVCRT__tzset();
|
2019-11-19 23:14:42 +01:00
|
|
|
#if _MSVCR_VER <= 90
|
2012-04-11 15:22:25 +02:00
|
|
|
if(MSVCRT__get_tzname(&tmp, str+ret, max-ret, mstm->tm_isdst ? 1 : 0))
|
|
|
|
return 0;
|
2019-11-19 23:14:42 +01:00
|
|
|
#else
|
|
|
|
if(MSVCRT__mbstowcs_s_l(&tmp, str+ret, max-ret,
|
|
|
|
mstm->tm_isdst ? tzname_dst : tzname_std,
|
|
|
|
MSVCRT__TRUNCATE, loc) == MSVCRT_STRUNCATE)
|
|
|
|
ret = max;
|
|
|
|
#endif
|
2017-05-03 12:37:26 +02:00
|
|
|
ret += tmp-1;
|
2012-04-11 15:22:25 +02:00
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
case 'W':
|
2019-11-13 22:07:57 +01:00
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
|
|
|
|
goto einval_error;
|
|
|
|
if(!MSVCRT_CHECK_PMT(mstm->tm_yday>=0 && mstm->tm_yday<=365))
|
2012-04-16 12:26:16 +02:00
|
|
|
goto einval_error;
|
|
|
|
if(*format == 'U')
|
|
|
|
tmp = mstm->tm_wday;
|
|
|
|
else if(!mstm->tm_wday)
|
|
|
|
tmp = 6;
|
|
|
|
else
|
|
|
|
tmp = mstm->tm_wday-1;
|
|
|
|
|
|
|
|
tmp = mstm->tm_yday/7 + (tmp<=mstm->tm_yday%7);
|
|
|
|
if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 2, 0, 53))
|
|
|
|
return 0;
|
|
|
|
break;
|
2012-04-11 15:22:25 +02:00
|
|
|
case '%':
|
|
|
|
str[ret++] = '%';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("unknown format %c\n", *format);
|
2019-11-13 22:07:57 +01:00
|
|
|
MSVCRT_INVALID_PMT("unknown format", MSVCRT_EINVAL);
|
2012-04-11 15:22:25 +02:00
|
|
|
goto einval_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret == max) {
|
|
|
|
if(max)
|
|
|
|
*str = 0;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
str[ret] = 0;
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
einval_error:
|
|
|
|
*str = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:14:42 +01:00
|
|
|
static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *format,
|
|
|
|
const struct MSVCRT_tm *mstm, MSVCRT___lc_time_data *time_data, MSVCRT__locale_t loc)
|
|
|
|
{
|
|
|
|
#if _MSVCR_VER <= 90
|
|
|
|
TRACE("(%p %ld %s %p %p %p)\n", str, max, format, mstm, time_data, loc);
|
|
|
|
return strftime_impl(str, max, format, mstm, time_data, loc);
|
|
|
|
#else
|
|
|
|
MSVCRT_wchar_t *s, *fmt;
|
|
|
|
MSVCRT_size_t len;
|
|
|
|
|
|
|
|
TRACE("(%p %ld %s %p %p %p)\n", str, max, format, mstm, time_data, loc);
|
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) return 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(max != 0)) return 0;
|
|
|
|
*str = 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(format != NULL)) return 0;
|
|
|
|
|
|
|
|
len = MSVCRT__mbstowcs_l( NULL, format, 0, loc ) + 1;
|
|
|
|
if (!len || !(fmt = MSVCRT_malloc( len*sizeof(MSVCRT_wchar_t) ))) return 0;
|
|
|
|
MSVCRT__mbstowcs_l(fmt, format, len, loc);
|
|
|
|
|
|
|
|
if ((s = MSVCRT_malloc( max*sizeof(MSVCRT_wchar_t) )))
|
|
|
|
{
|
|
|
|
len = strftime_impl( s, max, fmt, mstm, time_data, loc );
|
|
|
|
if (len)
|
|
|
|
len = MSVCRT__wcstombs_l( str, s, max, loc );
|
|
|
|
MSVCRT_free( s );
|
|
|
|
}
|
|
|
|
else len = 0;
|
|
|
|
|
|
|
|
MSVCRT_free( fmt );
|
|
|
|
return len;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:02 +01:00
|
|
|
#if _MSVCR_VER >= 80
|
2016-08-10 17:18:09 +02:00
|
|
|
/********************************************************************
|
2018-01-04 05:33:02 +01:00
|
|
|
* _strftime_l (MSVCR80.@)
|
2016-08-10 17:18:09 +02:00
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT__strftime_l( char *str, MSVCRT_size_t max, const char *format,
|
|
|
|
const struct MSVCRT_tm *mstm, MSVCRT__locale_t loc )
|
|
|
|
{
|
|
|
|
return strftime_helper(str, max, format, mstm, NULL, loc);
|
|
|
|
}
|
2018-01-04 05:33:02 +01:00
|
|
|
#endif
|
2016-08-10 17:18:09 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _Strftime (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL _Strftime(char *str, MSVCRT_size_t max, const char *format,
|
|
|
|
const struct MSVCRT_tm *mstm, MSVCRT___lc_time_data *time_data)
|
|
|
|
{
|
|
|
|
return strftime_helper(str, max, format, mstm, time_data, NULL);
|
|
|
|
}
|
|
|
|
|
2005-12-21 20:23:47 +01:00
|
|
|
/*********************************************************************
|
2006-01-14 17:22:03 +01:00
|
|
|
* strftime (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL MSVCRT_strftime( char *str, MSVCRT_size_t max, const char *format,
|
|
|
|
const struct MSVCRT_tm *mstm )
|
2006-01-14 17:22:03 +01:00
|
|
|
{
|
2016-08-10 17:18:09 +02:00
|
|
|
return strftime_helper(str, max, format, mstm, NULL, NULL);
|
2006-01-14 17:22:03 +01:00
|
|
|
}
|
|
|
|
|
2017-03-14 17:41:59 +01:00
|
|
|
static MSVCRT_size_t wcsftime_helper( MSVCRT_wchar_t *str, MSVCRT_size_t max,
|
|
|
|
const MSVCRT_wchar_t *format, const struct MSVCRT_tm *mstm,
|
|
|
|
MSVCRT___lc_time_data *time_data, MSVCRT__locale_t loc )
|
2006-01-23 19:29:15 +01:00
|
|
|
{
|
2019-11-19 23:14:42 +01:00
|
|
|
#if _MSVCR_VER <= 90
|
2006-03-23 20:35:52 +01:00
|
|
|
char *s, *fmt;
|
|
|
|
MSVCRT_size_t len;
|
2006-01-23 19:29:15 +01:00
|
|
|
|
2017-03-14 17:41:59 +01:00
|
|
|
TRACE("%p %ld %s %p %p %p\n", str, max, debugstr_w(format), mstm, time_data, loc);
|
2006-03-23 20:35:52 +01:00
|
|
|
|
2016-08-10 17:18:16 +02:00
|
|
|
len = MSVCRT__wcstombs_l( NULL, format, 0, loc ) + 1;
|
2006-03-23 20:35:52 +01:00
|
|
|
if (!(fmt = MSVCRT_malloc( len ))) return 0;
|
2016-08-10 17:18:16 +02:00
|
|
|
MSVCRT__wcstombs_l(fmt, format, len, loc);
|
2006-03-23 20:35:52 +01:00
|
|
|
|
|
|
|
if ((s = MSVCRT_malloc( max*4 )))
|
|
|
|
{
|
2019-11-19 23:14:42 +01:00
|
|
|
if (!strftime_impl( s, max*4, fmt, mstm, time_data, loc )) s[0] = 0;
|
2016-08-10 17:18:16 +02:00
|
|
|
len = MSVCRT__mbstowcs_l( str, s, max, loc );
|
2006-03-23 20:35:52 +01:00
|
|
|
MSVCRT_free( s );
|
|
|
|
}
|
|
|
|
else len = 0;
|
|
|
|
|
|
|
|
MSVCRT_free( fmt );
|
|
|
|
return len;
|
2019-11-19 23:14:42 +01:00
|
|
|
#else
|
|
|
|
TRACE("%p %ld %s %p %p %p\n", str, max, debugstr_w(format), mstm, time_data, loc);
|
|
|
|
return strftime_impl(str, max, format, mstm, time_data, loc);
|
|
|
|
#endif
|
2006-01-23 19:29:15 +01:00
|
|
|
}
|
|
|
|
|
2017-03-14 17:41:59 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcsftime_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT__wcsftime_l( MSVCRT_wchar_t *str, MSVCRT_size_t max,
|
|
|
|
const MSVCRT_wchar_t *format, const struct MSVCRT_tm *mstm, MSVCRT__locale_t loc )
|
|
|
|
{
|
|
|
|
return wcsftime_helper(str, max, format, mstm, NULL, loc);
|
|
|
|
}
|
|
|
|
|
2016-08-10 17:18:16 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* wcsftime (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT_wcsftime( MSVCRT_wchar_t *str, MSVCRT_size_t max,
|
|
|
|
const MSVCRT_wchar_t *format, const struct MSVCRT_tm *mstm )
|
|
|
|
{
|
2017-03-14 17:41:59 +01:00
|
|
|
return wcsftime_helper(str, max, format, mstm, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:02 +01:00
|
|
|
#if _MSVCR_VER >= 110
|
2017-03-14 17:41:59 +01:00
|
|
|
/*********************************************************************
|
2018-01-04 05:33:02 +01:00
|
|
|
* _Wcsftime (MSVCR110.@)
|
2017-03-14 17:41:59 +01:00
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL _Wcsftime(MSVCRT_wchar_t *str, MSVCRT_size_t max,
|
|
|
|
const MSVCRT_wchar_t *format, const struct MSVCRT_tm *mstm,
|
|
|
|
MSVCRT___lc_time_data *time_data)
|
|
|
|
{
|
|
|
|
return wcsftime_helper(str, max, format, mstm, time_data, NULL);
|
2016-08-10 17:18:16 +02:00
|
|
|
}
|
2018-01-04 05:33:02 +01:00
|
|
|
#endif
|
2016-08-10 17:18:16 +02:00
|
|
|
|
2012-04-11 15:21:32 +02:00
|
|
|
static char* asctime_buf(char *buf, const struct MSVCRT_tm *mstm)
|
|
|
|
{
|
|
|
|
static const char wday[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
|
|
|
static const char month[12][4] = {"Jan", "Feb", "Mar", "Apr", "May",
|
|
|
|
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
|
|
|
|
2014-05-12 14:34:51 +02:00
|
|
|
if (!mstm || mstm->tm_sec<0 || mstm->tm_sec>59
|
2012-04-11 15:21:32 +02:00
|
|
|
|| mstm->tm_min<0 || mstm->tm_min>59
|
|
|
|
|| mstm->tm_hour<0 || mstm->tm_hour>23
|
|
|
|
|| mstm->tm_mon<0 || mstm->tm_mon>11
|
|
|
|
|| mstm->tm_wday<0 || mstm->tm_wday>6
|
|
|
|
|| mstm->tm_year<0 || mstm->tm_mday<0
|
|
|
|
|| mstm->tm_mday>MonthLengths[IsLeapYear(1900+mstm->tm_year)][mstm->tm_mon]) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-11 14:14:24 +01:00
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
/* C89 (4.12.3.1) uses space-padding for day of month. */
|
|
|
|
MSVCRT__snprintf(buf, 26, "%s %s %2d %02d:%02d:%02d %c%03d\n", wday[mstm->tm_wday],
|
|
|
|
month[mstm->tm_mon], mstm->tm_mday, mstm->tm_hour, mstm->tm_min,
|
|
|
|
mstm->tm_sec, '1'+(mstm->tm_year+900)/1000, (900+mstm->tm_year)%1000);
|
|
|
|
#else
|
2012-04-11 15:21:32 +02:00
|
|
|
MSVCRT__snprintf(buf, 26, "%s %s %02d %02d:%02d:%02d %c%03d\n", wday[mstm->tm_wday],
|
|
|
|
month[mstm->tm_mon], mstm->tm_mday, mstm->tm_hour, mstm->tm_min,
|
|
|
|
mstm->tm_sec, '1'+(mstm->tm_year+900)/1000, (900+mstm->tm_year)%1000);
|
2018-03-11 14:14:24 +01:00
|
|
|
#endif
|
2012-04-11 15:21:32 +02:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:22:03 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* asctime (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
char * CDECL MSVCRT_asctime(const struct MSVCRT_tm *mstm)
|
2006-01-14 17:22:03 +01:00
|
|
|
{
|
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
|
2012-04-11 15:21:32 +02:00
|
|
|
/* asctime returns date in format that always has exactly 26 characters */
|
|
|
|
if (!data->asctime_buffer) {
|
|
|
|
data->asctime_buffer = MSVCRT_malloc(26);
|
|
|
|
if (!data->asctime_buffer) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_ENOMEM;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2006-01-14 17:22:03 +01:00
|
|
|
|
2012-04-11 15:21:32 +02:00
|
|
|
return asctime_buf(data->asctime_buffer, mstm);
|
2006-01-14 17:22:03 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 02:51:28 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* asctime_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_asctime_s(char* time, MSVCRT_size_t size, const struct MSVCRT_tm *mstm)
|
|
|
|
{
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(time != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (size) time[0] = 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(size >= 26)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mstm != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mstm->tm_sec >= 0 && mstm->tm_sec < 60)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mstm->tm_min >= 0 && mstm->tm_min < 60)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mstm->tm_hour >= 0 && mstm->tm_hour < 24)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mstm->tm_mon >= 0 && mstm->tm_mon < 12)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mstm->tm_wday >= 0 && mstm->tm_wday < 7)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mstm->tm_year >= 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mstm->tm_mday >= 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mstm->tm_mday <= MonthLengths[IsLeapYear(1900+mstm->tm_year)][mstm->tm_mon])) return MSVCRT_EINVAL;
|
2011-11-30 02:51:28 +01:00
|
|
|
|
2012-04-11 15:21:32 +02:00
|
|
|
asctime_buf(time, mstm);
|
2011-11-30 02:51:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:22:03 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wasctime (MSVCRT.@)
|
2005-12-21 20:23:47 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_wchar_t * CDECL MSVCRT__wasctime(const struct MSVCRT_tm *mstm)
|
2006-01-14 17:22:03 +01:00
|
|
|
{
|
2005-12-21 20:23:47 +01:00
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
2012-04-11 15:21:48 +02:00
|
|
|
char buffer[26];
|
2006-01-14 17:22:03 +01:00
|
|
|
|
2012-04-11 15:21:48 +02:00
|
|
|
if(!data->wasctime_buffer) {
|
|
|
|
data->wasctime_buffer = MSVCRT_malloc(26*sizeof(MSVCRT_wchar_t));
|
|
|
|
if(!data->wasctime_buffer) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_ENOMEM;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2005-12-21 20:23:47 +01:00
|
|
|
|
2012-04-11 15:21:48 +02:00
|
|
|
if(!asctime_buf(buffer, mstm))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, buffer, -1, data->wasctime_buffer, 26);
|
2005-12-21 20:23:47 +01:00
|
|
|
return data->wasctime_buffer;
|
|
|
|
}
|
|
|
|
|
2011-11-30 02:51:43 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wasctime_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wasctime_s(MSVCRT_wchar_t* time, MSVCRT_size_t size, const struct MSVCRT_tm *mstm)
|
|
|
|
{
|
2012-04-11 15:21:48 +02:00
|
|
|
char buffer[26];
|
|
|
|
int ret;
|
2011-11-30 02:51:43 +01:00
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(time != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (size) time[0] = 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(size >= 26)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mstm != NULL)) return MSVCRT_EINVAL;
|
2011-11-30 02:51:43 +01:00
|
|
|
|
2012-04-11 15:21:48 +02:00
|
|
|
ret = MSVCRT_asctime_s(buffer, sizeof(buffer), mstm);
|
2015-09-14 17:48:44 +02:00
|
|
|
if(ret)
|
2012-04-11 15:21:48 +02:00
|
|
|
return ret;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, buffer, -1, time, size);
|
2011-11-30 02:51:43 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:22:03 +01:00
|
|
|
/*********************************************************************
|
2009-05-23 11:06:29 +02:00
|
|
|
* _ctime64 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char * CDECL MSVCRT__ctime64(const MSVCRT___time64_t *time)
|
|
|
|
{
|
|
|
|
struct MSVCRT_tm *t;
|
|
|
|
t = MSVCRT__localtime64( time );
|
|
|
|
if (!t) return NULL;
|
|
|
|
return MSVCRT_asctime( t );
|
|
|
|
}
|
|
|
|
|
2010-11-20 14:49:53 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ctime64_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__ctime64_s(char *res, MSVCRT_size_t len, const MSVCRT___time64_t *time)
|
|
|
|
{
|
|
|
|
struct MSVCRT_tm *t;
|
2012-07-26 11:05:32 +02:00
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT( res != NULL )) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT( len >= 26 )) return MSVCRT_EINVAL;
|
2010-11-20 14:49:53 +01:00
|
|
|
res[0] = '\0';
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT( time != NULL )) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT( *time > 0 )) return MSVCRT_EINVAL;
|
|
|
|
|
2010-11-20 14:49:53 +01:00
|
|
|
t = MSVCRT__localtime64( time );
|
|
|
|
strcpy( res, MSVCRT_asctime( t ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-23 11:06:29 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _ctime32 (MSVCRT.@)
|
2006-01-14 17:22:03 +01:00
|
|
|
*/
|
2009-05-23 11:06:29 +02:00
|
|
|
char * CDECL MSVCRT__ctime32(const MSVCRT___time32_t *time)
|
2006-01-14 17:22:03 +01:00
|
|
|
{
|
2008-09-30 07:34:51 +02:00
|
|
|
struct MSVCRT_tm *t;
|
2009-05-23 11:06:29 +02:00
|
|
|
t = MSVCRT__localtime32( time );
|
2008-09-30 07:34:51 +02:00
|
|
|
if (!t) return NULL;
|
|
|
|
return MSVCRT_asctime( t );
|
2006-01-14 17:22:03 +01:00
|
|
|
}
|
|
|
|
|
2010-11-20 14:49:53 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ctime32_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__ctime32_s(char *res, MSVCRT_size_t len, const MSVCRT___time32_t *time)
|
|
|
|
{
|
|
|
|
struct MSVCRT_tm *t;
|
2012-07-26 11:05:32 +02:00
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT( res != NULL )) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT( len >= 26 )) return MSVCRT_EINVAL;
|
2010-11-20 14:49:53 +01:00
|
|
|
res[0] = '\0';
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT( time != NULL )) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT( *time > 0 )) return MSVCRT_EINVAL;
|
|
|
|
|
2010-11-20 14:49:53 +01:00
|
|
|
t = MSVCRT__localtime32( time );
|
|
|
|
strcpy( res, MSVCRT_asctime( t ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-23 11:06:29 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* ctime (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
#ifdef _WIN64
|
|
|
|
char * CDECL MSVCRT_ctime(const MSVCRT___time64_t *time)
|
|
|
|
{
|
|
|
|
return MSVCRT__ctime64( time );
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
char * CDECL MSVCRT_ctime(const MSVCRT___time32_t *time)
|
|
|
|
{
|
|
|
|
return MSVCRT__ctime32( time );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wctime64 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_wchar_t * CDECL MSVCRT__wctime64(const MSVCRT___time64_t *time)
|
|
|
|
{
|
|
|
|
return MSVCRT__wasctime( MSVCRT__localtime64(time) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wctime32 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_wchar_t * CDECL MSVCRT__wctime32(const MSVCRT___time32_t *time)
|
|
|
|
{
|
|
|
|
return MSVCRT__wasctime( MSVCRT__localtime32(time) );
|
|
|
|
}
|
|
|
|
|
2005-12-21 20:23:47 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wctime (MSVCRT.@)
|
|
|
|
*/
|
2009-05-23 11:06:29 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
MSVCRT_wchar_t * CDECL MSVCRT__wctime(const MSVCRT___time64_t *time)
|
2005-12-21 20:23:47 +01:00
|
|
|
{
|
2009-05-23 11:06:29 +02:00
|
|
|
return MSVCRT__wctime64( time );
|
2005-12-21 20:23:47 +01:00
|
|
|
}
|
2009-05-23 11:06:29 +02:00
|
|
|
#else
|
|
|
|
MSVCRT_wchar_t * CDECL MSVCRT__wctime(const MSVCRT___time32_t *time)
|
|
|
|
{
|
|
|
|
return MSVCRT__wctime32( time );
|
|
|
|
}
|
|
|
|
#endif
|
2014-04-16 16:15:21 +02:00
|
|
|
|
2015-09-14 17:48:44 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wctime64_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wctime64_s(MSVCRT_wchar_t *buf,
|
|
|
|
MSVCRT_size_t size, const MSVCRT___time64_t *time)
|
|
|
|
{
|
|
|
|
struct MSVCRT_tm tm;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!MSVCRT_CHECK_PMT(buf != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(size != 0)) return MSVCRT_EINVAL;
|
|
|
|
buf[0] = 0;
|
|
|
|
if(!MSVCRT_CHECK_PMT(time != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(*time >= 0)) return MSVCRT_EINVAL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(*time <= _MAX__TIME64_T)) return MSVCRT_EINVAL;
|
|
|
|
|
|
|
|
ret = _localtime64_s(&tm, time);
|
|
|
|
if(ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return MSVCRT__wasctime_s(buf, size, &tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wctime32_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wctime32_s(MSVCRT_wchar_t *buf, MSVCRT_size_t size,
|
|
|
|
const MSVCRT___time32_t *time)
|
|
|
|
{
|
|
|
|
struct MSVCRT_tm tm;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!MSVCRT_CHECK_PMT(buf != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(size != 0)) return MSVCRT_EINVAL;
|
|
|
|
buf[0] = 0;
|
|
|
|
if(!MSVCRT_CHECK_PMT(time != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(*time >= 0)) return MSVCRT_EINVAL;
|
|
|
|
|
|
|
|
ret = _localtime32_s(&tm, time);
|
|
|
|
if(ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return MSVCRT__wasctime_s(buf, size, &tm);
|
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:02 +01:00
|
|
|
#if _MSVCR_VER >= 80
|
|
|
|
|
2014-04-16 16:15:21 +02:00
|
|
|
/*********************************************************************
|
2018-01-04 05:33:02 +01:00
|
|
|
* _get_timezone (MSVCR80.@)
|
2014-04-16 16:15:21 +02:00
|
|
|
*/
|
|
|
|
int CDECL _get_timezone(LONG *timezone)
|
|
|
|
{
|
|
|
|
if(!MSVCRT_CHECK_PMT(timezone != NULL)) return MSVCRT_EINVAL;
|
|
|
|
|
|
|
|
*timezone = MSVCRT___timezone;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2018-01-04 05:33:02 +01:00
|
|
|
* _get_daylight (MSVCR80.@)
|
2014-04-16 16:15:21 +02:00
|
|
|
*/
|
|
|
|
int CDECL _get_daylight(int *hours)
|
|
|
|
{
|
|
|
|
if(!MSVCRT_CHECK_PMT(hours != NULL)) return MSVCRT_EINVAL;
|
|
|
|
|
|
|
|
*hours = MSVCRT___daylight;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-01-04 05:33:02 +01:00
|
|
|
|
|
|
|
#endif /* _MSVCR_VER >= 80 */
|
2018-04-18 20:38:18 +02:00
|
|
|
|
|
|
|
#if _MSVCR_VER >= 140
|
|
|
|
|
|
|
|
#define TIME_UTC 1
|
|
|
|
|
|
|
|
struct _timespec32
|
|
|
|
{
|
|
|
|
MSVCRT___time32_t tv_sec;
|
|
|
|
LONG tv_nsec;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _timespec64
|
|
|
|
{
|
|
|
|
MSVCRT___time64_t tv_sec;
|
|
|
|
LONG tv_nsec;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _timespec64_get (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
int CDECL _timespec64_get(struct _timespec64 *ts, int base)
|
|
|
|
{
|
|
|
|
ULONGLONG time;
|
|
|
|
FILETIME ft;
|
|
|
|
|
|
|
|
if(!MSVCRT_CHECK_PMT(ts != NULL)) return 0;
|
|
|
|
if(base != TIME_UTC) return 0;
|
|
|
|
|
|
|
|
GetSystemTimePreciseAsFileTime(&ft);
|
|
|
|
time = ((ULONGLONG)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
|
|
|
|
|
|
|
|
ts->tv_sec = time / TICKSPERSEC - SECS_1601_TO_1970;
|
|
|
|
ts->tv_nsec = time % TICKSPERSEC * 100;
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _timespec32_get (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
int CDECL _timespec32_get(struct _timespec32 *ts, int base)
|
|
|
|
{
|
|
|
|
struct _timespec64 ts64;
|
|
|
|
|
2020-07-14 20:22:40 +02:00
|
|
|
if(!MSVCRT_CHECK_PMT(ts != NULL)) return 0;
|
|
|
|
if(base != TIME_UTC) return 0;
|
|
|
|
|
2018-04-18 20:38:18 +02:00
|
|
|
if(_timespec64_get(&ts64, base) != base)
|
|
|
|
return 0;
|
|
|
|
if(ts64.tv_sec != (MSVCRT___time32_t)ts64.tv_sec)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ts->tv_sec = ts64.tv_sec;
|
|
|
|
ts->tv_nsec = ts64.tv_nsec;
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
#endif /* _MSVCR_VER >= 140 */
|