2 * msvcrt.dll date/time functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
8 * Copyright 2004 Hans Leidekker
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include <sys/timeb.h>
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
47 BOOL WINAPI
GetDaylightFlag(void);
49 static LONGLONG init_time
;
51 void msvcrt_init_clock(void)
53 LARGE_INTEGER systime
;
55 NtQuerySystemTime(&systime
);
56 init_time
= systime
.QuadPart
;
59 static const int MonthLengths
[2][12] =
61 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
62 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
66 static const int MAX_SECONDS
= 60;
68 static const int MAX_SECONDS
= 59;
71 static inline BOOL
IsLeapYear(int Year
)
73 return Year
% 4 == 0 && (Year
% 100 != 0 || Year
% 400 == 0);
76 static inline void write_invalid_msvcrt_tm( struct tm
*tm
)
89 /*********************************************************************
90 * _daylight (MSVCRT.@)
92 int MSVCRT___daylight
= 1;
94 /*********************************************************************
95 * _timezone (MSVCRT.@)
97 __msvcrt_long MSVCRT___timezone
= 28800;
99 /*********************************************************************
100 * _dstbias (MSVCRT.@)
102 __msvcrt_long MSVCRT__dstbias
= -3600;
104 /*********************************************************************
107 * Some apps (notably Mozilla) insist on writing to these, so the buffer
108 * must be large enough.
110 static char tzname_std
[64] = "PST";
111 static char tzname_dst
[64] = "PDT";
112 char *MSVCRT__tzname
[2] = { tzname_std
, tzname_dst
};
114 static TIME_ZONE_INFORMATION tzi
= {0};
115 /*********************************************************************
118 void CDECL
_tzset(void)
120 char *tz
= getenv("TZ");
125 BOOL neg_zone
= FALSE
;
127 memset(&tzi
, 0, sizeof(tzi
));
129 /* Parse timezone information: tzn[+|-]hh[:mm[:ss]][dzn] */
130 lstrcpynA(MSVCRT__tzname
[0], tz
, 3);
136 }else if(*tz
== '+') {
139 MSVCRT___timezone
= strtol(tz
, &tz
, 10)*3600;
141 MSVCRT___timezone
+= strtol(tz
+1, &tz
, 10)*60;
143 MSVCRT___timezone
+= strtol(tz
+1, &tz
, 10);
146 MSVCRT___timezone
= -MSVCRT___timezone
;
148 MSVCRT___daylight
= *tz
;
149 lstrcpynA(MSVCRT__tzname
[1], tz
, 3);
150 }else if(GetTimeZoneInformation(&tzi
) != TIME_ZONE_ID_INVALID
) {
151 MSVCRT___timezone
= tzi
.Bias
*60;
152 if(tzi
.StandardDate
.wMonth
)
153 MSVCRT___timezone
+= tzi
.StandardBias
*60;
155 if(tzi
.DaylightDate
.wMonth
) {
156 MSVCRT___daylight
= 1;
157 MSVCRT__dstbias
= (tzi
.DaylightBias
-tzi
.StandardBias
)*60;
159 MSVCRT___daylight
= 0;
163 if(!WideCharToMultiByte(CP_ACP
, 0, tzi
.StandardName
, -1, MSVCRT__tzname
[0],
164 sizeof(tzname_std
), NULL
, &error
) || error
)
165 *MSVCRT__tzname
[0] = 0;
166 if(!WideCharToMultiByte(CP_ACP
, 0, tzi
.DaylightName
, -1, MSVCRT__tzname
[1],
167 sizeof(tzname_dst
), NULL
, &error
) || error
)
168 *MSVCRT__tzname
[0] = 0;
173 static void _tzset_init(void)
175 static BOOL init
= FALSE
;
187 static BOOL
is_dst(const SYSTEMTIME
*st
)
189 TIME_ZONE_INFORMATION tmp
;
192 if(!MSVCRT___daylight
)
195 if(tzi
.DaylightDate
.wMonth
) {
197 }else if(st
->wYear
>= 2007) {
198 memset(&tmp
, 0, sizeof(tmp
));
199 tmp
.StandardDate
.wMonth
= 11;
200 tmp
.StandardDate
.wDay
= 1;
201 tmp
.StandardDate
.wHour
= 2;
202 tmp
.DaylightDate
.wMonth
= 3;
203 tmp
.DaylightDate
.wDay
= 2;
204 tmp
.DaylightDate
.wHour
= 2;
206 memset(&tmp
, 0, sizeof(tmp
));
207 tmp
.StandardDate
.wMonth
= 10;
208 tmp
.StandardDate
.wDay
= 5;
209 tmp
.StandardDate
.wHour
= 2;
210 tmp
.DaylightDate
.wMonth
= 4;
211 tmp
.DaylightDate
.wDay
= 1;
212 tmp
.DaylightDate
.wHour
= 2;
216 tmp
.StandardBias
= 0;
217 tmp
.DaylightBias
= MSVCRT__dstbias
/60;
218 if(!SystemTimeToTzSpecificLocalTime(&tmp
, st
, &out
))
221 return memcmp(st
, &out
, sizeof(SYSTEMTIME
));
224 #define SECSPERDAY 86400
225 /* 1601 to 1970 is 369 years plus 89 leap days */
226 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
227 #define TICKSPERSEC 10000000
228 #define TICKSPERMSEC 10000
229 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
231 static __time64_t
mktime_helper(struct tm
*mstm
, BOOL local
)
237 BOOL use_dst
= FALSE
;
239 ret
= mstm
->tm_year
+ mstm
->tm_mon
/12;
241 if(mstm
->tm_mon
< 0) {
246 if(ret
<70 || ret
>1100) {
251 memset(&st
, 0, sizeof(SYSTEMTIME
));
253 st
.wMonth
= mstm
->tm_mon
+1;
256 if(!SystemTimeToFileTime(&st
, &ft
)) {
261 ret
= ((__time64_t
)ft
.dwHighDateTime
<<32)+ft
.dwLowDateTime
;
262 ret
+= (__time64_t
)mstm
->tm_sec
*TICKSPERSEC
;
263 ret
+= (__time64_t
)mstm
->tm_min
*60*TICKSPERSEC
;
264 ret
+= (__time64_t
)mstm
->tm_hour
*60*60*TICKSPERSEC
;
265 ret
+= (__time64_t
)(mstm
->tm_mday
-1)*SECSPERDAY
*TICKSPERSEC
;
267 ft
.dwLowDateTime
= ret
& 0xffffffff;
268 ft
.dwHighDateTime
= ret
>> 32;
269 FileTimeToSystemTime(&ft
, &st
);
273 use_dst
= is_dst(&st
);
274 if((mstm
->tm_isdst
<=-1 && use_dst
) || (mstm
->tm_isdst
>=1)) {
277 ret
+= (__time64_t
)MSVCRT__dstbias
*TICKSPERSEC
;
279 ft
.dwLowDateTime
= ret
& 0xffffffff;
280 ft
.dwHighDateTime
= ret
>> 32;
281 FileTimeToSystemTime(&ft
, &tmp
);
289 }else if(mstm
->tm_isdst
==0 && use_dst
) {
290 ret
-= (__time64_t
)MSVCRT__dstbias
*TICKSPERSEC
;
291 ft
.dwLowDateTime
= ret
& 0xffffffff;
292 ft
.dwHighDateTime
= ret
>> 32;
293 FileTimeToSystemTime(&ft
, &st
);
294 ret
+= (__time64_t
)MSVCRT__dstbias
*TICKSPERSEC
;
296 ret
+= (__time64_t
)MSVCRT___timezone
*TICKSPERSEC
;
299 mstm
->tm_sec
= st
.wSecond
;
300 mstm
->tm_min
= st
.wMinute
;
301 mstm
->tm_hour
= st
.wHour
;
302 mstm
->tm_mday
= st
.wDay
;
303 mstm
->tm_mon
= st
.wMonth
-1;
304 mstm
->tm_year
= st
.wYear
-1900;
305 mstm
->tm_wday
= st
.wDayOfWeek
;
306 for(i
=mstm
->tm_yday
=0; i
<st
.wMonth
-1; i
++)
307 mstm
->tm_yday
+= MonthLengths
[IsLeapYear(st
.wYear
)][i
];
308 mstm
->tm_yday
+= st
.wDay
-1;
309 mstm
->tm_isdst
= use_dst
? 1 : 0;
311 if(ret
< TICKS_1601_TO_1970
) {
315 ret
= (ret
-TICKS_1601_TO_1970
)/TICKSPERSEC
;
319 /**********************************************************************
320 * _mktime64 (MSVCRT.@)
322 __time64_t CDECL
_mktime64(struct tm
*mstm
)
324 return mktime_helper(mstm
, TRUE
);
327 /**********************************************************************
328 * _mktime32 (MSVCRT.@)
330 __time32_t CDECL
_mktime32(struct tm
*mstm
)
332 __time64_t ret
= _mktime64( mstm
);
333 return ret
== (__time32_t
)ret
? ret
: -1;
336 /**********************************************************************
337 * _mkgmtime64 (MSVCRT.@)
339 * time->tm_isdst value is ignored
341 __time64_t CDECL
_mkgmtime64(struct tm
*time
)
343 return mktime_helper(time
, FALSE
);
346 /**********************************************************************
347 * _mkgmtime32 (MSVCRT.@)
349 __time32_t CDECL
_mkgmtime32(struct tm
*time
)
351 __time64_t ret
= _mkgmtime64(time
);
352 return ret
== (__time32_t
)ret
? ret
: -1;
355 /*********************************************************************
356 * _localtime64_s (MSVCRT.@)
358 int CDECL
_localtime64_s(struct tm
*res
, const __time64_t
*secs
)
365 if (!res
|| !secs
|| *secs
< 0 || *secs
> _MAX__TIME64_T
)
368 write_invalid_msvcrt_tm(res
);
375 time
= (*secs
- MSVCRT___timezone
) * (ULONGLONG
)TICKSPERSEC
+ TICKS_1601_TO_1970
;
377 ft
.dwHighDateTime
= (UINT
)(time
>> 32);
378 ft
.dwLowDateTime
= (UINT
)time
;
379 FileTimeToSystemTime(&ft
, &st
);
381 res
->tm_isdst
= is_dst(&st
) ? 1 : 0;
383 time
-= MSVCRT__dstbias
* (ULONGLONG
)TICKSPERSEC
;
384 ft
.dwHighDateTime
= (UINT
)(time
>> 32);
385 ft
.dwLowDateTime
= (UINT
)time
;
386 FileTimeToSystemTime(&ft
, &st
);
389 res
->tm_sec
= st
.wSecond
;
390 res
->tm_min
= st
.wMinute
;
391 res
->tm_hour
= st
.wHour
;
392 res
->tm_mday
= st
.wDay
;
393 res
->tm_year
= st
.wYear
- 1900;
394 res
->tm_mon
= st
.wMonth
- 1;
395 res
->tm_wday
= st
.wDayOfWeek
;
396 for (i
= res
->tm_yday
= 0; i
< st
.wMonth
- 1; i
++)
397 res
->tm_yday
+= MonthLengths
[IsLeapYear(st
.wYear
)][i
];
398 res
->tm_yday
+= st
.wDay
- 1;
403 /*********************************************************************
404 * _localtime64 (MSVCRT.@)
406 struct tm
* CDECL
_localtime64(const __time64_t
* secs
)
408 thread_data_t
*data
= msvcrt_get_thread_data();
410 if(!data
->time_buffer
)
411 data
->time_buffer
= malloc(sizeof(struct tm
));
413 if(_localtime64_s(data
->time_buffer
, secs
))
415 return data
->time_buffer
;
418 /*********************************************************************
419 * _localtime32 (MSVCRT.@)
421 struct tm
* CDECL
_localtime32(const __time32_t
* secs
)
429 return _localtime64( &secs64
);
432 /*********************************************************************
433 * _localtime32_s (MSVCRT.@)
435 int CDECL
_localtime32_s(struct tm
*time
, const __time32_t
*secs
)
439 if (!time
|| !secs
|| *secs
< 0)
442 write_invalid_msvcrt_tm(time
);
449 return _localtime64_s(time
, &secs64
);
452 /*********************************************************************
453 * _gmtime64 (MSVCRT.@)
455 int CDECL
_gmtime64_s(struct tm
*res
, const __time64_t
*secs
)
462 if (!res
|| !secs
|| *secs
< 0 || *secs
> _MAX__TIME64_T
) {
464 write_invalid_msvcrt_tm(res
);
471 time
= *secs
* (ULONGLONG
)TICKSPERSEC
+ TICKS_1601_TO_1970
;
473 ft
.dwHighDateTime
= (UINT
)(time
>> 32);
474 ft
.dwLowDateTime
= (UINT
)time
;
476 FileTimeToSystemTime(&ft
, &st
);
478 res
->tm_sec
= st
.wSecond
;
479 res
->tm_min
= st
.wMinute
;
480 res
->tm_hour
= st
.wHour
;
481 res
->tm_mday
= st
.wDay
;
482 res
->tm_year
= st
.wYear
- 1900;
483 res
->tm_mon
= st
.wMonth
- 1;
484 res
->tm_wday
= st
.wDayOfWeek
;
485 for (i
= res
->tm_yday
= 0; i
< st
.wMonth
- 1; i
++) {
486 res
->tm_yday
+= MonthLengths
[IsLeapYear(st
.wYear
)][i
];
489 res
->tm_yday
+= st
.wDay
- 1;
495 /*********************************************************************
496 * _gmtime64 (MSVCRT.@)
498 struct tm
* CDECL
_gmtime64(const __time64_t
*secs
)
500 thread_data_t
* const data
= msvcrt_get_thread_data();
502 if(!data
->time_buffer
)
503 data
->time_buffer
= malloc(sizeof(struct tm
));
505 if(_gmtime64_s(data
->time_buffer
, secs
))
507 return data
->time_buffer
;
510 /*********************************************************************
511 * _gmtime32_s (MSVCRT.@)
513 int CDECL
_gmtime32_s(struct tm
*res
, const __time32_t
*secs
)
519 return _gmtime64_s(res
, &secs64
);
521 return _gmtime64_s(res
, NULL
);
524 /*********************************************************************
525 * _gmtime32 (MSVCRT.@)
527 struct tm
* CDECL
_gmtime32(const __time32_t
* secs
)
535 return _gmtime64( &secs64
);
538 /**********************************************************************
539 * _strdate (MSVCRT.@)
541 char* CDECL
_strdate(char* date
)
543 GetDateFormatA(LOCALE_NEUTRAL
, 0, NULL
, "MM'/'dd'/'yy", date
, 9);
547 /**********************************************************************
548 * _strdate_s (MSVCRT.@)
550 int CDECL
_strdate_s(char* date
, size_t size
)
569 /**********************************************************************
570 * _wstrdate (MSVCRT.@)
572 wchar_t* CDECL
_wstrdate(wchar_t* date
)
574 GetDateFormatW(LOCALE_NEUTRAL
, 0, NULL
, L
"MM'/'dd'/'yy", date
, 9);
578 /**********************************************************************
579 * _wstrdate_s (MSVCRT.@)
581 int CDECL
_wstrdate_s(wchar_t* date
, size_t size
)
600 /*********************************************************************
601 * _strtime (MSVCRT.@)
603 char* CDECL
_strtime(char* time
)
605 GetTimeFormatA(LOCALE_NEUTRAL
, 0, NULL
, "HH':'mm':'ss", time
, 9);
609 /*********************************************************************
610 * _strtime_s (MSVCRT.@)
612 int CDECL
_strtime_s(char* time
, size_t size
)
631 /*********************************************************************
632 * _wstrtime (MSVCRT.@)
634 wchar_t* CDECL
_wstrtime(wchar_t* time
)
636 GetTimeFormatW(LOCALE_NEUTRAL
, 0, NULL
, L
"HH':'mm':'ss", time
, 9);
640 /*********************************************************************
641 * _wstrtime_s (MSVCRT.@)
643 int CDECL
_wstrtime_s(wchar_t* time
, size_t size
)
662 /*********************************************************************
665 clock_t CDECL
clock(void)
667 LARGE_INTEGER systime
;
669 NtQuerySystemTime(&systime
);
670 return (systime
.QuadPart
- init_time
) / (TICKSPERSEC
/ CLOCKS_PER_SEC
);
673 /*********************************************************************
674 * _difftime64 (MSVCRT.@)
676 double CDECL
_difftime64(__time64_t time1
, __time64_t time2
)
678 return (double)(time1
- time2
);
681 /*********************************************************************
682 * _difftime32 (MSVCRT.@)
684 double CDECL
_difftime32(__time32_t time1
, __time32_t time2
)
686 return (double)(time1
- time2
);
689 /*********************************************************************
690 * _ftime64 (MSVCRT.@)
692 void CDECL
_ftime64(struct __timeb64
*buf
)
699 GetSystemTimeAsFileTime(&ft
);
701 time
= ((ULONGLONG
)ft
.dwHighDateTime
<< 32) | ft
.dwLowDateTime
;
703 buf
->time
= time
/ TICKSPERSEC
- SECS_1601_TO_1970
;
704 buf
->millitm
= (time
% TICKSPERSEC
) / TICKSPERMSEC
;
705 buf
->timezone
= MSVCRT___timezone
/ 60;
706 buf
->dstflag
= GetDaylightFlag();
709 /*********************************************************************
710 * _ftime64_s (MSVCRT.@)
712 int CDECL
_ftime64_s(struct __timeb64
*buf
)
714 if (!MSVCRT_CHECK_PMT( buf
!= NULL
)) return EINVAL
;
719 /*********************************************************************
720 * _ftime32 (MSVCRT.@)
722 void CDECL
_ftime32(struct __timeb32
*buf
)
724 struct __timeb64 buf64
;
727 buf
->time
= buf64
.time
;
728 buf
->millitm
= buf64
.millitm
;
729 buf
->timezone
= buf64
.timezone
;
730 buf
->dstflag
= buf64
.dstflag
;
733 /*********************************************************************
734 * _ftime32_s (MSVCRT.@)
736 int CDECL
_ftime32_s(struct __timeb32
*buf
)
738 if (!MSVCRT_CHECK_PMT( buf
!= NULL
)) return EINVAL
;
743 /*********************************************************************
746 __time64_t CDECL
_time64(__time64_t
*buf
)
754 return buf
? *buf
= curtime
: curtime
;
757 /*********************************************************************
760 __time32_t CDECL
_time32(__time32_t
*buf
)
768 return buf
? *buf
= curtime
: curtime
;
771 /*********************************************************************
772 * __p__daylight (MSVCRT.@)
774 int * CDECL
__p__daylight(void)
776 return &MSVCRT___daylight
;
779 /*********************************************************************
780 * __p__dstbias (MSVCRT.@)
782 __msvcrt_long
* CDECL
__p__dstbias(void)
784 return &MSVCRT__dstbias
;
788 /*********************************************************************
789 * _get_dstbias (MSVCR80.@)
791 int CDECL
_get_dstbias(int *seconds
)
793 if (!MSVCRT_CHECK_PMT(seconds
!= NULL
)) return EINVAL
;
794 *seconds
= MSVCRT__dstbias
;
799 /*********************************************************************
800 * __p__timezone (MSVCRT.@)
802 __msvcrt_long
* CDECL
__p__timezone(void)
804 return &MSVCRT___timezone
;
807 /*********************************************************************
808 * _get_tzname (MSVCRT.@)
810 int CDECL
_get_tzname(size_t *ret
, char *buf
, size_t bufsize
, int index
)
817 timezone
= tzname_std
;
820 timezone
= tzname_dst
;
827 if(!ret
|| (!buf
&& bufsize
> 0) || (buf
&& !bufsize
))
833 *ret
= strlen(timezone
)+1;
842 strcpy(buf
, timezone
);
846 /*********************************************************************
847 * __p_tzname (MSVCRT.@)
849 char ** CDECL
__p__tzname(void)
851 return MSVCRT__tzname
;
855 #define STRFTIME_CHAR char
856 #define STRFTIME_TD(td, name) td->str.names.name
858 #define STRFTIME_CHAR wchar_t
859 #define STRFTIME_TD(td, name) td->wstr.names.name
862 #define strftime_str(a,b,c,d) strftime_nstr(a,b,c,d,SIZE_MAX)
863 static inline BOOL
strftime_nstr(STRFTIME_CHAR
*str
, size_t *pos
,
864 size_t max
, const STRFTIME_CHAR
*src
, size_t len
)
882 static inline BOOL
strftime_int(STRFTIME_CHAR
*str
, size_t *pos
, size_t max
,
883 int src
, int prec
, int l
, int h
)
887 if(!MSVCRT_CHECK_PMT(src
>=l
&& src
<=h
)) {
893 len
= _snprintf(str
+*pos
, max
-*pos
, "%0*d", prec
, src
);
895 len
= _snwprintf(str
+*pos
, max
-*pos
, L
"%0*d", prec
, src
);
907 static inline BOOL
strftime_format(STRFTIME_CHAR
*str
, size_t *pos
, size_t max
,
908 const struct tm
*mstm
, __lc_time_data
*time_data
, const STRFTIME_CHAR
*format
)
913 while(*format
&& ret
)
916 while(format
[0] == format
[count
]) count
++;
920 if(count
% 2 == 0) break;
924 while(format
[count
] && format
[count
] != '\'') count
++;
926 ret
= strftime_nstr(str
, pos
, max
, format
, count
);
927 if(!ret
) return FALSE
;
928 if(format
[count
] == '\'') count
++;
933 if(!MSVCRT_CHECK_PMT(mstm
->tm_wday
>=0 && mstm
->tm_wday
<=6))
942 ret
= strftime_int(str
, pos
, max
, mstm
->tm_mday
, count
==1 ? 0 : 2, 1, 31);
945 ret
= strftime_str(str
, pos
, max
, STRFTIME_TD(time_data
, short_wday
)[mstm
->tm_wday
]);
948 ret
= strftime_nstr(str
, pos
, max
, format
, count
-4);
950 ret
= strftime_str(str
, pos
, max
, STRFTIME_TD(time_data
, wday
)[mstm
->tm_wday
]);
957 if(!MSVCRT_CHECK_PMT(mstm
->tm_mon
>=0 && mstm
->tm_mon
<=11))
966 ret
= strftime_int(str
, pos
, max
, mstm
->tm_mon
+1, count
==1 ? 0 : 2, 1, 12);
969 ret
= strftime_str(str
, pos
, max
, STRFTIME_TD(time_data
, short_mon
)[mstm
->tm_mon
]);
972 ret
= strftime_nstr(str
, pos
, max
, format
, count
-4);
974 ret
= strftime_str(str
, pos
, max
, STRFTIME_TD(time_data
, mon
)[mstm
->tm_mon
]);
982 if(!MSVCRT_CHECK_PMT(mstm
->tm_year
>= -1900 && mstm
->tm_year
<= 8099))
984 if(!MSVCRT_CHECK_PMT(mstm
->tm_year
>= 0))
994 ret
= strftime_nstr(str
, pos
, max
, format
, 1);
998 ret
= strftime_nstr(str
, pos
, max
, format
, count
-2);
1000 ret
= strftime_int(str
, pos
, max
, (mstm
->tm_year
+1900)%100, 2, 0, 99);
1003 ret
= strftime_nstr(str
, pos
, max
, format
, count
-4);
1005 ret
= strftime_int(str
, pos
, max
, mstm
->tm_year
+1900, 4, 0, 9999);
1010 if(!MSVCRT_CHECK_PMT(mstm
->tm_hour
>=0 && mstm
->tm_hour
<=23))
1016 ret
= strftime_nstr(str
, pos
, max
, format
, count
-2);
1018 ret
= strftime_int(str
, pos
, max
, (mstm
->tm_hour
+ 11) % 12 + 1,
1019 count
== 1 ? 0 : 2, 1, 12);
1023 ret
= strftime_nstr(str
, pos
, max
, format
, count
-2);
1025 ret
= strftime_int(str
, pos
, max
, mstm
->tm_hour
, count
== 1 ? 0 : 2, 0, 23);
1029 ret
= strftime_nstr(str
, pos
, max
, format
, count
-2);
1031 ret
= strftime_int(str
, pos
, max
, mstm
->tm_min
, count
== 1 ? 0 : 2, 0, 59);
1035 ret
= strftime_nstr(str
, pos
, max
, format
, count
-2);
1037 ret
= strftime_int(str
, pos
, max
, mstm
->tm_sec
, count
== 1 ? 0 : 2, 0, MAX_SECONDS
);
1042 if(!MSVCRT_CHECK_PMT(mstm
->tm_hour
>=0 && mstm
->tm_hour
<=23))
1047 ret
= strftime_nstr(str
, pos
, max
,
1048 mstm
->tm_hour
< 12 ? STRFTIME_TD(time_data
, am
) : STRFTIME_TD(time_data
, pm
),
1049 (*format
== 't' && count
== 1) ? 1 : SIZE_MAX
);
1052 ret
= strftime_nstr(str
, pos
, max
, format
, count
);
1062 static inline BOOL
strftime_tzdiff(STRFTIME_CHAR
*str
, size_t *pos
, size_t max
, BOOL is_dst
)
1064 __msvcrt_long tz
= MSVCRT___timezone
+ (is_dst
? MSVCRT__dstbias
: 0);
1075 str
[(*pos
)++] = sign
;
1076 if(!strftime_int(str
, pos
, max
, tz
/60/60, 2, 0, 99))
1078 return strftime_int(str
, pos
, max
, tz
/60%60, 2, 0, 59);
1082 static size_t strftime_impl(STRFTIME_CHAR
*str
, size_t max
,
1083 const STRFTIME_CHAR
*format
, const struct tm
*mstm
,
1084 __lc_time_data
*time_data
, _locale_t loc
)
1088 int year
= mstm
? mstm
->tm_year
+ 1900 : -1;
1090 if(!str
|| !format
) {
1098 time_data
= loc
? loc
->locinfo
->lc_time_curr
: get_locinfo()->lc_time_curr
;
1100 for(ret
=0; *format
&& ret
<max
; format
++) {
1101 if(*format
!= '%') {
1102 if(_isleadbyte_l((unsigned char)*format
, loc
)) {
1103 str
[ret
++] = *(format
++);
1104 if(ret
== max
) continue;
1105 if(!MSVCRT_CHECK_PMT(str
[ret
]))
1108 str
[ret
++] = *format
;
1113 if(*format
== '#') {
1120 if(!MSVCRT_CHECK_PMT(mstm
))
1126 if(time_data
== &cloc_time_data
&& !alternate
)
1128 tmp
= strftime_impl(str
+ret
, max
-ret
, L
"%a %b %e %T %Y", mstm
, time_data
, loc
);
1135 if(!strftime_format(str
, &ret
, max
, mstm
, time_data
,
1136 alternate
? STRFTIME_TD(time_data
, date
) : STRFTIME_TD(time_data
, short_date
)))
1140 if(!strftime_format(str
, &ret
, max
, mstm
, time_data
, STRFTIME_TD(time_data
, time
)))
1144 if(!strftime_format(str
, &ret
, max
, mstm
, time_data
,
1145 alternate
? STRFTIME_TD(time_data
, date
) : STRFTIME_TD(time_data
, short_date
)))
1149 if(!strftime_format(str
, &ret
, max
, mstm
, time_data
, STRFTIME_TD(time_data
, time
)))
1153 if(!MSVCRT_CHECK_PMT(mstm
->tm_wday
>=0 && mstm
->tm_wday
<=6))
1155 if(!strftime_str(str
, &ret
, max
, STRFTIME_TD(time_data
, short_wday
)[mstm
->tm_wday
]))
1159 if(!MSVCRT_CHECK_PMT(mstm
->tm_wday
>=0 && mstm
->tm_wday
<=6))
1161 if(!strftime_str(str
, &ret
, max
, STRFTIME_TD(time_data
, wday
)[mstm
->tm_wday
]))
1168 if(!MSVCRT_CHECK_PMT(mstm
->tm_mon
>=0 && mstm
->tm_mon
<=11))
1170 if(!strftime_str(str
, &ret
, max
, STRFTIME_TD(time_data
, short_mon
)[mstm
->tm_mon
]))
1174 if(!MSVCRT_CHECK_PMT(mstm
->tm_mon
>=0 && mstm
->tm_mon
<=11))
1176 if(!strftime_str(str
, &ret
, max
, STRFTIME_TD(time_data
, mon
)[mstm
->tm_mon
]))
1181 if(!MSVCRT_CHECK_PMT(year
>=0 && year
<=9999))
1183 if(!strftime_int(str
, &ret
, max
, year
/100, alternate
? 0 : 2, 0, 99))
1188 if(!strftime_int(str
, &ret
, max
, mstm
->tm_mday
, alternate
? 0 : 2, 1, 31))
1193 if(!MSVCRT_CHECK_PMT(year
>=0 && year
<=9999))
1195 if(!strftime_int(str
, &ret
, max
, mstm
->tm_mon
+1, alternate
? 0 : 2, 1, 12))
1199 if(!strftime_int(str
, &ret
, max
, mstm
->tm_mday
, alternate
? 0 : 2, 1, 31))
1203 if(!strftime_int(str
, &ret
, max
, year
%100, alternate
? 0 : 2, 0, 99))
1207 if(!strftime_int(str
, &ret
, max
, mstm
->tm_mday
, alternate
? 0 : 2, 1, 31))
1209 if(!alternate
&& str
[ret
-2] == '0')
1213 if(!strftime_int(str
, &ret
, max
, year
, alternate
? 0 : 4, 0, 9999))
1217 if(!strftime_int(str
, &ret
, max
, mstm
->tm_mon
+1, alternate
? 0 : 2, 1, 12))
1221 if(!strftime_int(str
, &ret
, max
, mstm
->tm_mday
, alternate
? 0 : 2, 1, 31))
1226 if(!MSVCRT_CHECK_PMT(year
>=0 && year
<=9999))
1231 int iso_year
= year
;
1232 int iso_days
= mstm
->tm_yday
- (mstm
->tm_wday
? mstm
->tm_wday
: 7) + 4;
1234 iso_days
+= 365 + IsLeapYear(--iso_year
);
1235 else if(iso_days
>= 365 + IsLeapYear(iso_year
))
1236 iso_days
-= 365 + IsLeapYear(iso_year
++);
1238 if(*format
== 'G') {
1239 if(!strftime_int(str
, &ret
, max
, iso_year
, 4, 0, 9999))
1241 } else if(*format
== 'g') {
1242 if(!strftime_int(str
, &ret
, max
, iso_year
%100, 2, 0, 99))
1245 if(!strftime_int(str
, &ret
, max
, iso_days
/7 + 1, alternate
? 0 : 2, 0, 53))
1252 if(!strftime_int(str
, &ret
, max
, mstm
->tm_hour
, alternate
? 0 : 2, 0, 23))
1256 if(!MSVCRT_CHECK_PMT(mstm
->tm_hour
>=0 && mstm
->tm_hour
<=23))
1258 if(!strftime_int(str
, &ret
, max
, (mstm
->tm_hour
+ 11) % 12 + 1,
1259 alternate
? 0 : 2, 1, 12))
1263 if(!strftime_int(str
, &ret
, max
, mstm
->tm_yday
+1, alternate
? 0 : 3, 1, 366))
1267 if(!strftime_int(str
, &ret
, max
, mstm
->tm_mon
+1, alternate
? 0 : 2, 1, 12))
1271 if(!strftime_int(str
, &ret
, max
, mstm
->tm_min
, alternate
? 0 : 2, 0, 59))
1280 if(!MSVCRT_CHECK_PMT(mstm
->tm_hour
>=0 && mstm
->tm_hour
<=23))
1282 if(!strftime_str(str
, &ret
, max
, mstm
->tm_hour
<12 ?
1283 STRFTIME_TD(time_data
, am
) : STRFTIME_TD(time_data
, pm
)))
1288 if(time_data
== &cloc_time_data
)
1290 if(!MSVCRT_CHECK_PMT(mstm
->tm_hour
>=0 && mstm
->tm_hour
<=23))
1292 if(!strftime_int(str
, &ret
, max
, (mstm
->tm_hour
+ 11) % 12 + 1,
1293 alternate
? 0 : 2, 1, 12))
1297 if(!strftime_int(str
, &ret
, max
, mstm
->tm_min
, alternate
? 0 : 2, 0, 59))
1301 if(!strftime_int(str
, &ret
, max
, mstm
->tm_sec
, alternate
? 0 : 2, 0, MAX_SECONDS
))
1305 if(!strftime_str(str
, &ret
, max
, mstm
->tm_hour
<12 ?
1306 STRFTIME_TD(time_data
, am
) : STRFTIME_TD(time_data
, pm
)))
1311 if(!strftime_format(str
, &ret
, max
, mstm
, time_data
, STRFTIME_TD(time_data
, time
)))
1316 if(!strftime_int(str
, &ret
, max
, mstm
->tm_hour
, alternate
? 0 : 2, 0, 23))
1320 if(!strftime_int(str
, &ret
, max
, mstm
->tm_min
, alternate
? 0 : 2, 0, 59))
1325 if(!strftime_int(str
, &ret
, max
, mstm
->tm_sec
, alternate
? 0 : 2, 0, MAX_SECONDS
))
1333 if(!strftime_int(str
, &ret
, max
, mstm
->tm_hour
, alternate
? 0 : 2, 0, 23))
1337 if(!strftime_int(str
, &ret
, max
, mstm
->tm_min
, alternate
? 0 : 2, 0, 59))
1341 if(!strftime_int(str
, &ret
, max
, mstm
->tm_sec
, alternate
? 0 : 2, 0, MAX_SECONDS
))
1345 if(!MSVCRT_CHECK_PMT(mstm
->tm_wday
>=0 && mstm
->tm_wday
<=6))
1347 tmp
= mstm
->tm_wday
? mstm
->tm_wday
: 7;
1348 if(!strftime_int(str
, &ret
, max
, tmp
, 0, 1, 7))
1353 if(!strftime_int(str
, &ret
, max
, mstm
->tm_wday
, 0, 0, 6))
1358 if(!MSVCRT_CHECK_PMT(year
>=0 && year
<=9999))
1360 if(!MSVCRT_CHECK_PMT(year
>=1900))
1363 if(!strftime_int(str
, &ret
, max
, year
%100, alternate
? 0 : 2, 0, 99))
1367 if(!strftime_int(str
, &ret
, max
, year
, alternate
? 0 : 4, 0, 9999))
1373 if(!strftime_tzdiff(str
, &ret
, max
, mstm
->tm_isdst
))
1379 #if _MSVCR_VER <= 90
1380 if(_get_tzname(&tmp
, str
+ret
, max
-ret
, mstm
->tm_isdst
? 1 : 0))
1383 if(_mbstowcs_s_l(&tmp
, str
+ret
, max
-ret
,
1384 mstm
->tm_isdst
? tzname_dst
: tzname_std
,
1385 _TRUNCATE
, loc
) == STRUNCATE
)
1392 if(!MSVCRT_CHECK_PMT(mstm
->tm_wday
>=0 && mstm
->tm_wday
<=6))
1394 if(!MSVCRT_CHECK_PMT(mstm
->tm_yday
>=0 && mstm
->tm_yday
<=365))
1397 tmp
= mstm
->tm_wday
;
1398 else if(!mstm
->tm_wday
)
1401 tmp
= mstm
->tm_wday
-1;
1403 tmp
= mstm
->tm_yday
/7 + (tmp
<=mstm
->tm_yday
%7);
1404 if(!strftime_int(str
, &ret
, max
, tmp
, alternate
? 0 : 2, 0, 53))
1411 WARN("unknown format %c\n", *format
);
1412 MSVCRT_INVALID_PMT("unknown format", EINVAL
);
1432 static size_t strftime_helper(char *str
, size_t max
, const char *format
,
1433 const struct tm
*mstm
, __lc_time_data
*time_data
, _locale_t loc
)
1435 #if _MSVCR_VER <= 90
1436 TRACE("(%p %Iu %s %p %p %p)\n", str
, max
, format
, mstm
, time_data
, loc
);
1437 return strftime_impl(str
, max
, format
, mstm
, time_data
, loc
);
1443 TRACE("(%p %Iu %s %p %p %p)\n", str
, max
, format
, mstm
, time_data
, loc
);
1445 if (!MSVCRT_CHECK_PMT(str
!= NULL
)) return 0;
1446 if (!MSVCRT_CHECK_PMT(max
!= 0)) return 0;
1448 if (!MSVCRT_CHECK_PMT(format
!= NULL
)) return 0;
1450 cp
= (loc
? loc
->locinfo
: get_locinfo())->lc_id
[LC_TIME
].wCodePage
;
1452 len
= MultiByteToWideChar( cp
, 0, format
, -1, NULL
, 0 );
1458 fmt
= malloc( len
*sizeof(wchar_t) );
1460 MultiByteToWideChar( cp
, 0, format
, -1, fmt
, len
);
1462 if ((s
= malloc( max
*sizeof(wchar_t) )))
1464 len
= strftime_impl( s
, max
, fmt
, mstm
, time_data
, loc
);
1467 len
= WideCharToMultiByte( cp
, 0, s
, -1, str
, max
, NULL
, NULL
);
1469 else *_errno() = EILSEQ
;
1480 #if _MSVCR_VER >= 80
1481 /********************************************************************
1482 * _strftime_l (MSVCR80.@)
1484 size_t CDECL
_strftime_l( char *str
, size_t max
, const char *format
,
1485 const struct tm
*mstm
, _locale_t loc
)
1487 return strftime_helper(str
, max
, format
, mstm
, NULL
, loc
);
1491 /*********************************************************************
1492 * _Strftime (MSVCRT.@)
1494 size_t CDECL
_Strftime(char *str
, size_t max
, const char *format
,
1495 const struct tm
*mstm
, void *time_data
)
1497 return strftime_helper(str
, max
, format
, mstm
, time_data
, NULL
);
1500 /*********************************************************************
1501 * strftime (MSVCRT.@)
1503 size_t CDECL
strftime( char *str
, size_t max
, const char *format
,
1504 const struct tm
*mstm
)
1506 return strftime_helper(str
, max
, format
, mstm
, NULL
, NULL
);
1509 static size_t wcsftime_helper( wchar_t *str
, size_t max
,
1510 const wchar_t *format
, const struct tm
*mstm
,
1511 __lc_time_data
*time_data
, _locale_t loc
)
1513 #if _MSVCR_VER <= 90
1517 TRACE("%p %Iu %s %p %p %p\n", str
, max
, debugstr_w(format
), mstm
, time_data
, loc
);
1519 len
= _wcstombs_l( NULL
, format
, 0, loc
) + 1;
1520 if (!(fmt
= malloc( len
))) return 0;
1521 _wcstombs_l(fmt
, format
, len
, loc
);
1523 if ((s
= malloc( max
*4 )))
1525 if (!strftime_impl( s
, max
*4, fmt
, mstm
, time_data
, loc
)) s
[0] = 0;
1526 len
= _mbstowcs_l( str
, s
, max
, loc
);
1534 TRACE("%p %Iu %s %p %p %p\n", str
, max
, debugstr_w(format
), mstm
, time_data
, loc
);
1535 return strftime_impl(str
, max
, format
, mstm
, time_data
, loc
);
1539 /*********************************************************************
1540 * _wcsftime_l (MSVCRT.@)
1542 size_t CDECL
_wcsftime_l( wchar_t *str
, size_t max
,
1543 const wchar_t *format
, const struct tm
*mstm
, _locale_t loc
)
1545 return wcsftime_helper(str
, max
, format
, mstm
, NULL
, loc
);
1548 /*********************************************************************
1549 * wcsftime (MSVCRT.@)
1551 size_t CDECL
wcsftime( wchar_t *str
, size_t max
,
1552 const wchar_t *format
, const struct tm
*mstm
)
1554 return wcsftime_helper(str
, max
, format
, mstm
, NULL
, NULL
);
1557 #if _MSVCR_VER >= 110
1558 /*********************************************************************
1559 * _Wcsftime (MSVCR110.@)
1561 size_t CDECL
_Wcsftime(wchar_t *str
, size_t max
,
1562 const wchar_t *format
, const struct tm
*mstm
,
1563 __lc_time_data
*time_data
)
1565 return wcsftime_helper(str
, max
, format
, mstm
, time_data
, NULL
);
1569 static char* asctime_buf(char *buf
, const struct tm
*mstm
)
1571 static const char wday
[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
1572 static const char month
[12][4] = {"Jan", "Feb", "Mar", "Apr", "May",
1573 "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1575 if (!mstm
|| mstm
->tm_sec
<0 || mstm
->tm_sec
>59
1576 || mstm
->tm_min
<0 || mstm
->tm_min
>59
1577 || mstm
->tm_hour
<0 || mstm
->tm_hour
>23
1578 || mstm
->tm_mon
<0 || mstm
->tm_mon
>11
1579 || mstm
->tm_wday
<0 || mstm
->tm_wday
>6
1580 || mstm
->tm_year
<0 || mstm
->tm_mday
<0
1581 || mstm
->tm_mday
>MonthLengths
[IsLeapYear(1900+mstm
->tm_year
)][mstm
->tm_mon
]) {
1587 /* C89 (4.12.3.1) uses space-padding for day of month. */
1588 _snprintf(buf
, 26, "%s %s %2d %02d:%02d:%02d %c%03d\n", wday
[mstm
->tm_wday
],
1589 month
[mstm
->tm_mon
], mstm
->tm_mday
, mstm
->tm_hour
, mstm
->tm_min
,
1590 mstm
->tm_sec
, '1'+(mstm
->tm_year
+900)/1000, (900+mstm
->tm_year
)%1000);
1592 _snprintf(buf
, 26, "%s %s %02d %02d:%02d:%02d %c%03d\n", wday
[mstm
->tm_wday
],
1593 month
[mstm
->tm_mon
], mstm
->tm_mday
, mstm
->tm_hour
, mstm
->tm_min
,
1594 mstm
->tm_sec
, '1'+(mstm
->tm_year
+900)/1000, (900+mstm
->tm_year
)%1000);
1599 /*********************************************************************
1600 * asctime (MSVCRT.@)
1602 char * CDECL
asctime(const struct tm
*mstm
)
1604 thread_data_t
*data
= msvcrt_get_thread_data();
1606 /* asctime returns date in format that always has exactly 26 characters */
1607 if (!data
->asctime_buffer
) {
1608 data
->asctime_buffer
= malloc(26);
1609 if (!data
->asctime_buffer
) {
1615 return asctime_buf(data
->asctime_buffer
, mstm
);
1618 /*********************************************************************
1619 * asctime_s (MSVCRT.@)
1621 int CDECL
asctime_s(char* time
, size_t size
, const struct tm
*mstm
)
1623 if (!MSVCRT_CHECK_PMT(time
!= NULL
)) return EINVAL
;
1624 if (size
) time
[0] = 0;
1625 if (!MSVCRT_CHECK_PMT(size
>= 26)) return EINVAL
;
1626 if (!MSVCRT_CHECK_PMT(mstm
!= NULL
)) return EINVAL
;
1627 if (!MSVCRT_CHECK_PMT(mstm
->tm_sec
>= 0 && mstm
->tm_sec
< 60)) return EINVAL
;
1628 if (!MSVCRT_CHECK_PMT(mstm
->tm_min
>= 0 && mstm
->tm_min
< 60)) return EINVAL
;
1629 if (!MSVCRT_CHECK_PMT(mstm
->tm_hour
>= 0 && mstm
->tm_hour
< 24)) return EINVAL
;
1630 if (!MSVCRT_CHECK_PMT(mstm
->tm_mon
>= 0 && mstm
->tm_mon
< 12)) return EINVAL
;
1631 if (!MSVCRT_CHECK_PMT(mstm
->tm_wday
>= 0 && mstm
->tm_wday
< 7)) return EINVAL
;
1632 if (!MSVCRT_CHECK_PMT(mstm
->tm_year
>= 0)) return EINVAL
;
1633 if (!MSVCRT_CHECK_PMT(mstm
->tm_mday
>= 0)) return EINVAL
;
1634 if (!MSVCRT_CHECK_PMT(mstm
->tm_mday
<= MonthLengths
[IsLeapYear(1900+mstm
->tm_year
)][mstm
->tm_mon
])) return EINVAL
;
1636 asctime_buf(time
, mstm
);
1640 /*********************************************************************
1641 * _wasctime (MSVCRT.@)
1643 wchar_t * CDECL
_wasctime(const struct tm
*mstm
)
1645 thread_data_t
*data
= msvcrt_get_thread_data();
1648 if(!data
->wasctime_buffer
) {
1649 data
->wasctime_buffer
= malloc(26*sizeof(wchar_t));
1650 if(!data
->wasctime_buffer
) {
1656 if(!asctime_buf(buffer
, mstm
))
1659 MultiByteToWideChar(CP_ACP
, 0, buffer
, -1, data
->wasctime_buffer
, 26);
1660 return data
->wasctime_buffer
;
1663 /*********************************************************************
1664 * _wasctime_s (MSVCRT.@)
1666 int CDECL
_wasctime_s(wchar_t* time
, size_t size
, const struct tm
*mstm
)
1671 if (!MSVCRT_CHECK_PMT(time
!= NULL
)) return EINVAL
;
1672 if (size
) time
[0] = 0;
1673 if (!MSVCRT_CHECK_PMT(size
>= 26)) return EINVAL
;
1674 if (!MSVCRT_CHECK_PMT(mstm
!= NULL
)) return EINVAL
;
1676 ret
= asctime_s(buffer
, sizeof(buffer
), mstm
);
1679 MultiByteToWideChar(CP_ACP
, 0, buffer
, -1, time
, size
);
1683 /*********************************************************************
1684 * _ctime64 (MSVCRT.@)
1686 char * CDECL
_ctime64(const __time64_t
*time
)
1689 t
= _localtime64( time
);
1690 if (!t
) return NULL
;
1691 return asctime( t
);
1694 /*********************************************************************
1695 * _ctime64_s (MSVCRT.@)
1697 int CDECL
_ctime64_s(char *res
, size_t len
, const __time64_t
*time
)
1701 if (!MSVCRT_CHECK_PMT( res
!= NULL
)) return EINVAL
;
1702 if (!MSVCRT_CHECK_PMT( len
>= 26 )) return EINVAL
;
1704 if (!MSVCRT_CHECK_PMT( time
!= NULL
)) return EINVAL
;
1705 if (!MSVCRT_CHECK_PMT( *time
> 0 )) return EINVAL
;
1707 t
= _localtime64( time
);
1708 strcpy( res
, asctime( t
) );
1712 /*********************************************************************
1713 * _ctime32 (MSVCRT.@)
1715 char * CDECL
_ctime32(const __time32_t
*time
)
1718 t
= _localtime32( time
);
1719 if (!t
) return NULL
;
1720 return asctime( t
);
1723 /*********************************************************************
1724 * _ctime32_s (MSVCRT.@)
1726 int CDECL
_ctime32_s(char *res
, size_t len
, const __time32_t
*time
)
1730 if (!MSVCRT_CHECK_PMT( res
!= NULL
)) return EINVAL
;
1731 if (!MSVCRT_CHECK_PMT( len
>= 26 )) return EINVAL
;
1733 if (!MSVCRT_CHECK_PMT( time
!= NULL
)) return EINVAL
;
1734 if (!MSVCRT_CHECK_PMT( *time
> 0 )) return EINVAL
;
1736 t
= _localtime32( time
);
1737 strcpy( res
, asctime( t
) );
1741 /*********************************************************************
1742 * _wctime64 (MSVCRT.@)
1744 wchar_t * CDECL
_wctime64(const __time64_t
*time
)
1746 return _wasctime( _localtime64(time
) );
1749 /*********************************************************************
1750 * _wctime32 (MSVCRT.@)
1752 wchar_t * CDECL
_wctime32(const __time32_t
*time
)
1754 return _wasctime( _localtime32(time
) );
1757 /*********************************************************************
1758 * _wctime64_s (MSVCRT.@)
1760 int CDECL
_wctime64_s(wchar_t *buf
,
1761 size_t size
, const __time64_t
*time
)
1766 if(!MSVCRT_CHECK_PMT(buf
!= NULL
)) return EINVAL
;
1767 if(!MSVCRT_CHECK_PMT(size
!= 0)) return EINVAL
;
1769 if(!MSVCRT_CHECK_PMT(time
!= NULL
)) return EINVAL
;
1770 if(!MSVCRT_CHECK_PMT(*time
>= 0)) return EINVAL
;
1771 if(!MSVCRT_CHECK_PMT(*time
<= _MAX__TIME64_T
)) return EINVAL
;
1773 ret
= _localtime64_s(&tm
, time
);
1777 return _wasctime_s(buf
, size
, &tm
);
1780 /*********************************************************************
1781 * _wctime32_s (MSVCRT.@)
1783 int CDECL
_wctime32_s(wchar_t *buf
, size_t size
,
1784 const __time32_t
*time
)
1789 if(!MSVCRT_CHECK_PMT(buf
!= NULL
)) return EINVAL
;
1790 if(!MSVCRT_CHECK_PMT(size
!= 0)) return EINVAL
;
1792 if(!MSVCRT_CHECK_PMT(time
!= NULL
)) return EINVAL
;
1793 if(!MSVCRT_CHECK_PMT(*time
>= 0)) return EINVAL
;
1795 ret
= _localtime32_s(&tm
, time
);
1799 return _wasctime_s(buf
, size
, &tm
);
1802 #if _MSVCR_VER >= 80
1804 /*********************************************************************
1805 * _get_timezone (MSVCR80.@)
1807 int CDECL
_get_timezone(LONG
*timezone
)
1809 if(!MSVCRT_CHECK_PMT(timezone
!= NULL
)) return EINVAL
;
1811 *timezone
= MSVCRT___timezone
;
1815 /*********************************************************************
1816 * _get_daylight (MSVCR80.@)
1818 int CDECL
_get_daylight(int *hours
)
1820 if(!MSVCRT_CHECK_PMT(hours
!= NULL
)) return EINVAL
;
1822 *hours
= MSVCRT___daylight
;
1826 #endif /* _MSVCR_VER >= 80 */
1828 #if _MSVCR_VER >= 140
1844 /*********************************************************************
1845 * _timespec64_get (UCRTBASE.@)
1847 int CDECL
_timespec64_get(struct _timespec64
*ts
, int base
)
1852 if(!MSVCRT_CHECK_PMT(ts
!= NULL
)) return 0;
1853 if(base
!= TIME_UTC
) return 0;
1855 GetSystemTimePreciseAsFileTime(&ft
);
1856 time
= ((ULONGLONG
)ft
.dwHighDateTime
<< 32) | ft
.dwLowDateTime
;
1858 ts
->tv_sec
= time
/ TICKSPERSEC
- SECS_1601_TO_1970
;
1859 ts
->tv_nsec
= time
% TICKSPERSEC
* 100;
1863 /*********************************************************************
1864 * _timespec32_get (UCRTBASE.@)
1866 int CDECL
_timespec32_get(struct _timespec32
*ts
, int base
)
1868 struct _timespec64 ts64
;
1870 if(!MSVCRT_CHECK_PMT(ts
!= NULL
)) return 0;
1871 if(base
!= TIME_UTC
) return 0;
1873 if(_timespec64_get(&ts64
, base
) != base
)
1875 if(ts64
.tv_sec
!= (__time32_t
)ts64
.tv_sec
)
1878 ts
->tv_sec
= ts64
.tv_sec
;
1879 ts
->tv_nsec
= ts64
.tv_nsec
;
1882 #endif /* _MSVCR_VER >= 140 */