dmsynth: Add stubbed IKsControl interface to DirectMusicSynth object.
[wine] / dlls / msvcrt / time.c
1 /*
2  * msvcrt.dll date/time functions
3  *
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
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include "config.h"
26
27 #define _POSIX_PTHREAD_SEMANTICS /* switch to a 2 arg style asctime_r on Solaris */
28 #include <time.h>
29 #ifdef HAVE_SYS_TIMES_H
30 # include <sys/times.h>
31 #endif
32 #include <limits.h>
33
34 #include "msvcrt.h"
35 #include "mtdll.h"
36 #include "winbase.h"
37 #include "winnls.h"
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
42
43 static const int MonthLengths[2][12] =
44 {
45     { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
46     { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
47 };
48
49 static inline int IsLeapYear(int Year)
50 {
51     return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0);
52 }
53
54 static inline void msvcrt_tm_to_unix( struct tm *dest, const struct MSVCRT_tm *src )
55 {
56     memset( dest, 0, sizeof(*dest) );
57     dest->tm_sec   = src->tm_sec;
58     dest->tm_min   = src->tm_min;
59     dest->tm_hour  = src->tm_hour;
60     dest->tm_mday  = src->tm_mday;
61     dest->tm_mon   = src->tm_mon;
62     dest->tm_year  = src->tm_year;
63     dest->tm_wday  = src->tm_wday;
64     dest->tm_yday  = src->tm_yday;
65     dest->tm_isdst = src->tm_isdst;
66 }
67
68 static inline void unix_tm_to_msvcrt( struct MSVCRT_tm *dest, const struct tm *src )
69 {
70     memset( dest, 0, sizeof(*dest) );
71     dest->tm_sec   = src->tm_sec;
72     dest->tm_min   = src->tm_min;
73     dest->tm_hour  = src->tm_hour;
74     dest->tm_mday  = src->tm_mday;
75     dest->tm_mon   = src->tm_mon;
76     dest->tm_year  = src->tm_year;
77     dest->tm_wday  = src->tm_wday;
78     dest->tm_yday  = src->tm_yday;
79     dest->tm_isdst = src->tm_isdst;
80 }
81
82 static inline void write_invalid_msvcrt_tm( struct MSVCRT_tm *tm )
83 {
84     tm->tm_sec = -1;
85     tm->tm_min = -1;
86     tm->tm_hour = -1;
87     tm->tm_mday = -1;
88     tm->tm_mon = -1;
89     tm->tm_year = -1;
90     tm->tm_wday = -1;
91     tm->tm_yday = -1;
92     tm->tm_isdst = -1;
93 }
94
95 #define SECSPERDAY        86400
96 /* 1601 to 1970 is 369 years plus 89 leap days */
97 #define SECS_1601_TO_1970  ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
98 #define TICKSPERSEC       10000000
99 #define TICKSPERMSEC      10000
100 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
101
102 /**********************************************************************
103  *              _mktime64 (MSVCRT.@)
104  */
105 MSVCRT___time64_t CDECL MSVCRT__mktime64(struct MSVCRT_tm *mstm)
106 {
107     time_t secs;
108     struct tm tm;
109
110     msvcrt_tm_to_unix( &tm, mstm );
111     secs = mktime( &tm );
112     unix_tm_to_msvcrt( mstm, &tm );
113
114     return secs < 0 ? -1 : secs;
115 }
116
117 /**********************************************************************
118  *              _mktime32 (MSVCRT.@)
119  */
120 MSVCRT___time32_t CDECL MSVCRT__mktime32(struct MSVCRT_tm *mstm)
121 {
122     return MSVCRT__mktime64( mstm );
123 }
124
125 /**********************************************************************
126  *              mktime (MSVCRT.@)
127  */
128 #ifdef _WIN64
129 MSVCRT___time64_t CDECL MSVCRT_mktime(struct MSVCRT_tm *mstm)
130 {
131     return MSVCRT__mktime64( mstm );
132 }
133 #else
134 MSVCRT___time32_t CDECL MSVCRT_mktime(struct MSVCRT_tm *mstm)
135 {
136     return MSVCRT__mktime32( mstm );
137 }
138 #endif
139
140 /**********************************************************************
141  *              _mkgmtime64 (MSVCRT.@)
142  *
143  * time->tm_isdst value is ignored
144  */
145 MSVCRT___time64_t CDECL MSVCRT__mkgmtime64(struct MSVCRT_tm *time)
146 {
147     SYSTEMTIME st;
148     FILETIME ft;
149     MSVCRT___time64_t ret;
150     int i;
151
152     st.wMilliseconds = 0;
153     st.wSecond = time->tm_sec;
154     st.wMinute = time->tm_min;
155     st.wHour = time->tm_hour;
156     st.wDay = time->tm_mday;
157     st.wMonth = time->tm_mon+1;
158     st.wYear = time->tm_year+1900;
159
160     if(!SystemTimeToFileTime(&st, &ft))
161         return -1;
162
163     FileTimeToSystemTime(&ft, &st);
164     time->tm_wday = st.wDayOfWeek;
165
166     for(i=time->tm_yday=0; i<st.wMonth-1; i++)
167         time->tm_yday += MonthLengths[IsLeapYear(st.wYear)][i];
168     time->tm_yday += st.wDay-1;
169
170     ret = ((MSVCRT___time64_t)ft.dwHighDateTime<<32)+ft.dwLowDateTime;
171     ret = (ret-TICKS_1601_TO_1970)/TICKSPERSEC;
172     return ret;
173 }
174
175 /**********************************************************************
176  *              _mkgmtime32 (MSVCRT.@)
177  */
178 MSVCRT___time32_t CDECL MSVCRT__mkgmtime32(struct MSVCRT_tm *time)
179 {
180     return MSVCRT__mkgmtime64(time);
181 }
182
183 /**********************************************************************
184  *              _mkgmtime (MSVCRT.@)
185  */
186 #ifdef _WIN64
187 MSVCRT___time64_t CDECL MSVCRT__mkgmtime(struct MSVCRT_tm *time)
188 {
189     return MSVCRT__mkgmtime64(time);
190 }
191 #else
192 MSVCRT___time32_t CDECL MSVCRT__mkgmtime(struct MSVCRT_tm *time)
193 {
194     return MSVCRT__mkgmtime32(time);
195 }
196 #endif
197
198 /*********************************************************************
199  *      _localtime64 (MSVCRT.@)
200  */
201 struct MSVCRT_tm* CDECL MSVCRT__localtime64(const MSVCRT___time64_t* secs)
202 {
203     struct tm *tm;
204     thread_data_t *data;
205     time_t seconds = *secs;
206
207     if (seconds < 0) return NULL;
208
209     _mlock(_TIME_LOCK);
210     if (!(tm = localtime( &seconds))) {
211         _munlock(_TIME_LOCK);
212         return NULL;
213     }
214
215     data = msvcrt_get_thread_data();
216     if(!data->time_buffer)
217         data->time_buffer = MSVCRT_malloc(sizeof(struct MSVCRT_tm));
218
219     unix_tm_to_msvcrt( data->time_buffer, tm );
220     _munlock(_TIME_LOCK);
221
222     return data->time_buffer;
223 }
224
225 /*********************************************************************
226  *      _localtime64_s (MSVCRT.@)
227  */
228 int CDECL _localtime64_s(struct MSVCRT_tm *time, const MSVCRT___time64_t *secs)
229 {
230     struct tm *tm;
231     time_t seconds;
232
233     if (!time || !secs || *secs < 0 || *secs > _MAX__TIME64_T)
234     {
235         if (time)
236             write_invalid_msvcrt_tm(time);
237
238         *MSVCRT__errno() = MSVCRT_EINVAL;
239         return MSVCRT_EINVAL;
240     }
241
242     seconds = *secs;
243
244     _mlock(_TIME_LOCK);
245     if (!(tm = localtime(&seconds)))
246     {
247         _munlock(_TIME_LOCK);
248         *MSVCRT__errno() = MSVCRT_EINVAL;
249         return MSVCRT_EINVAL;
250     }
251
252     unix_tm_to_msvcrt(time, tm);
253     _munlock(_TIME_LOCK);
254     return 0;
255 }
256
257 /*********************************************************************
258  *      _localtime32 (MSVCRT.@)
259  */
260 struct MSVCRT_tm* CDECL MSVCRT__localtime32(const MSVCRT___time32_t* secs)
261 {
262     MSVCRT___time64_t secs64 = *secs;
263     return MSVCRT__localtime64( &secs64 );
264 }
265
266 /*********************************************************************
267  *      _localtime32_s (MSVCRT.@)
268  */
269 int CDECL _localtime32_s(struct MSVCRT_tm *time, const MSVCRT___time32_t *secs)
270 {
271     MSVCRT___time64_t secs64;
272
273     if (!time || !secs || *secs < 0)
274     {
275         if (time)
276             write_invalid_msvcrt_tm(time);
277
278         *MSVCRT__errno() = MSVCRT_EINVAL;
279         return MSVCRT_EINVAL;
280     }
281
282     secs64 = *secs;
283     return _localtime64_s(time, &secs64);
284 }
285
286 /*********************************************************************
287  *      localtime (MSVCRT.@)
288  */
289 #ifdef _WIN64
290 struct MSVCRT_tm* CDECL MSVCRT_localtime(const MSVCRT___time64_t* secs)
291 {
292     return MSVCRT__localtime64( secs );
293 }
294 #else
295 struct MSVCRT_tm* CDECL MSVCRT_localtime(const MSVCRT___time32_t* secs)
296 {
297     return MSVCRT__localtime32( secs );
298 }
299 #endif
300
301 /*********************************************************************
302  *      _gmtime64 (MSVCRT.@)
303  */
304 int CDECL MSVCRT__gmtime64_s(struct MSVCRT_tm *res, const MSVCRT___time64_t *secs)
305 {
306     int i;
307     FILETIME ft;
308     SYSTEMTIME st;
309     ULONGLONG time;
310
311     if (!res || !secs || *secs < 0) {
312         if (res) {
313             write_invalid_msvcrt_tm(res);
314         }
315
316         *MSVCRT__errno() = MSVCRT_EINVAL;
317         return MSVCRT_EINVAL;
318     }
319
320     time = *secs * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
321
322     ft.dwHighDateTime = (UINT)(time >> 32);
323     ft.dwLowDateTime  = (UINT)time;
324
325     FileTimeToSystemTime(&ft, &st);
326
327     res->tm_sec  = st.wSecond;
328     res->tm_min  = st.wMinute;
329     res->tm_hour = st.wHour;
330     res->tm_mday = st.wDay;
331     res->tm_year = st.wYear - 1900;
332     res->tm_mon  = st.wMonth - 1;
333     res->tm_wday = st.wDayOfWeek;
334     for (i = res->tm_yday = 0; i < st.wMonth - 1; i++) {
335         res->tm_yday += MonthLengths[IsLeapYear(st.wYear)][i];
336     }
337
338     res->tm_yday += st.wDay - 1;
339     res->tm_isdst = 0;
340
341     return 0;
342 }
343
344 /*********************************************************************
345  *      _gmtime64 (MSVCRT.@)
346  */
347 struct MSVCRT_tm* CDECL MSVCRT__gmtime64(const MSVCRT___time64_t *secs)
348 {
349     thread_data_t * const data = msvcrt_get_thread_data();
350
351     if(!data->time_buffer)
352         data->time_buffer = MSVCRT_malloc(sizeof(struct MSVCRT_tm));
353
354     if(MSVCRT__gmtime64_s(data->time_buffer, secs))
355         return NULL;
356     return data->time_buffer;
357 }
358
359 /*********************************************************************
360  *      _gmtime32_s (MSVCRT.@)
361  */
362 int CDECL MSVCRT__gmtime32_s(struct MSVCRT_tm *res, const MSVCRT___time32_t *secs)
363 {
364     MSVCRT___time64_t secs64;
365
366     if(secs) {
367         secs64 = *secs;
368         return MSVCRT__gmtime64_s(res, &secs64);
369     }
370     return MSVCRT__gmtime64_s(res, NULL);
371 }
372
373 /*********************************************************************
374  *      _gmtime32 (MSVCRT.@)
375  */
376 struct MSVCRT_tm* CDECL MSVCRT__gmtime32(const MSVCRT___time32_t* secs)
377 {
378     MSVCRT___time64_t secs64;
379
380     if(!secs)
381         return NULL;
382
383     secs64 = *secs;
384     return MSVCRT__gmtime64( &secs64 );
385 }
386
387 /*********************************************************************
388  *      gmtime (MSVCRT.@)
389  */
390 #ifdef _WIN64
391 struct MSVCRT_tm* CDECL MSVCRT_gmtime(const MSVCRT___time64_t* secs)
392 {
393     return MSVCRT__gmtime64( secs );
394 }
395 #else
396 struct MSVCRT_tm* CDECL MSVCRT_gmtime(const MSVCRT___time32_t* secs)
397 {
398     return MSVCRT__gmtime32( secs );
399 }
400 #endif
401
402 /**********************************************************************
403  *              _strdate (MSVCRT.@)
404  */
405 char* CDECL MSVCRT__strdate(char* date)
406 {
407   static const char format[] = "MM'/'dd'/'yy";
408
409   GetDateFormatA(LOCALE_NEUTRAL, 0, NULL, format, date, 9);
410
411   return date;
412 }
413
414 /**********************************************************************
415  *              _strdate_s (MSVCRT.@)
416  */
417 int CDECL _strdate_s(char* date, MSVCRT_size_t size)
418 {
419     if(date && size)
420         date[0] = '\0';
421
422     if(!date) {
423         *MSVCRT__errno() = MSVCRT_EINVAL;
424         return MSVCRT_EINVAL;
425     }
426
427     if(size < 9) {
428         *MSVCRT__errno() = MSVCRT_ERANGE;
429         return MSVCRT_ERANGE;
430     }
431
432     MSVCRT__strdate(date);
433     return 0;
434 }
435
436 /**********************************************************************
437  *              _wstrdate (MSVCRT.@)
438  */
439 MSVCRT_wchar_t* CDECL MSVCRT__wstrdate(MSVCRT_wchar_t* date)
440 {
441   static const WCHAR format[] = { 'M','M','\'','/','\'','d','d','\'','/','\'','y','y',0 };
442
443   GetDateFormatW(LOCALE_NEUTRAL, 0, NULL, format, date, 9);
444
445   return date;
446 }
447
448 /**********************************************************************
449  *              _wstrdate_s (MSVCRT.@)
450  */
451 int CDECL _wstrdate_s(MSVCRT_wchar_t* date, MSVCRT_size_t size)
452 {
453     if(date && size)
454         date[0] = '\0';
455
456     if(!date) {
457         *MSVCRT__errno() = MSVCRT_EINVAL;
458         return MSVCRT_EINVAL;
459     }
460
461     if(size < 9) {
462         *MSVCRT__errno() = MSVCRT_ERANGE;
463         return MSVCRT_ERANGE;
464     }
465
466     MSVCRT__wstrdate(date);
467     return 0;
468 }
469
470 /*********************************************************************
471  *              _strtime (MSVCRT.@)
472  */
473 char* CDECL MSVCRT__strtime(char* time)
474 {
475   static const char format[] = "HH':'mm':'ss";
476
477   GetTimeFormatA(LOCALE_NEUTRAL, 0, NULL, format, time, 9); 
478
479   return time;
480 }
481
482 /*********************************************************************
483  *              _strtime_s (MSVCRT.@)
484  */
485 int CDECL _strtime_s(char* time, MSVCRT_size_t size)
486 {
487     if(time && size)
488         time[0] = '\0';
489
490     if(!time) {
491         *MSVCRT__errno() = MSVCRT_EINVAL;
492         return MSVCRT_EINVAL;
493     }
494
495     if(size < 9) {
496         *MSVCRT__errno() = MSVCRT_ERANGE;
497         return MSVCRT_ERANGE;
498     }
499
500     MSVCRT__strtime(time);
501     return 0;
502 }
503
504 /*********************************************************************
505  *              _wstrtime (MSVCRT.@)
506  */
507 MSVCRT_wchar_t* CDECL MSVCRT__wstrtime(MSVCRT_wchar_t* time)
508 {
509   static const WCHAR format[] = { 'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0 };
510
511   GetTimeFormatW(LOCALE_NEUTRAL, 0, NULL, format, time, 9);
512
513   return time;
514 }
515
516 /*********************************************************************
517  *              _wstrtime_s (MSVCRT.@)
518  */
519 int CDECL _wstrtime_s(MSVCRT_wchar_t* time, MSVCRT_size_t size)
520 {
521     if(time && size)
522         time[0] = '\0';
523
524     if(!time) {
525         *MSVCRT__errno() = MSVCRT_EINVAL;
526         return MSVCRT_EINVAL;
527     }
528
529     if(size < 9) {
530         *MSVCRT__errno() = MSVCRT_ERANGE;
531         return MSVCRT_ERANGE;
532     }
533
534     MSVCRT__wstrtime(time);
535     return 0;
536 }
537
538 /*********************************************************************
539  *              clock (MSVCRT.@)
540  */
541 MSVCRT_clock_t CDECL MSVCRT_clock(void)
542 {
543   FILETIME ftc, fte, ftk, ftu;
544   ULONGLONG utime, ktime;
545  
546   MSVCRT_clock_t clock;
547
548   GetProcessTimes(GetCurrentProcess(), &ftc, &fte, &ftk, &ftu);
549
550   ktime = ((ULONGLONG)ftk.dwHighDateTime << 32) | ftk.dwLowDateTime;
551   utime = ((ULONGLONG)ftu.dwHighDateTime << 32) | ftu.dwLowDateTime;
552
553   clock = (utime + ktime) / (TICKSPERSEC / MSVCRT_CLOCKS_PER_SEC);
554
555   return clock;
556 }
557
558 /*********************************************************************
559  *              _difftime64 (MSVCRT.@)
560  */
561 double CDECL MSVCRT__difftime64(MSVCRT___time64_t time1, MSVCRT___time64_t time2)
562 {
563   return (double)(time1 - time2);
564 }
565
566 /*********************************************************************
567  *              _difftime32 (MSVCRT.@)
568  */
569 double CDECL MSVCRT__difftime32(MSVCRT___time32_t time1, MSVCRT___time32_t time2)
570 {
571   return (double)(time1 - time2);
572 }
573
574 /*********************************************************************
575  *              difftime (MSVCRT.@)
576  */
577 #ifdef _WIN64
578 double CDECL MSVCRT_difftime(MSVCRT___time64_t time1, MSVCRT___time64_t time2)
579 {
580     return MSVCRT__difftime64( time1, time2 );
581 }
582 #else
583 double CDECL MSVCRT_difftime(MSVCRT___time32_t time1, MSVCRT___time32_t time2)
584 {
585     return MSVCRT__difftime32( time1, time2 );
586 }
587 #endif
588
589 /*********************************************************************
590  *              _ftime64 (MSVCRT.@)
591  */
592 void CDECL MSVCRT__ftime64(struct MSVCRT___timeb64 *buf)
593 {
594   TIME_ZONE_INFORMATION tzinfo;
595   FILETIME ft;
596   ULONGLONG time;
597
598   DWORD tzid = GetTimeZoneInformation(&tzinfo);
599   GetSystemTimeAsFileTime(&ft);
600
601   time = ((ULONGLONG)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
602
603   buf->time = time / TICKSPERSEC - SECS_1601_TO_1970;
604   buf->millitm = (time % TICKSPERSEC) / TICKSPERMSEC;
605   buf->timezone = tzinfo.Bias +
606       ( tzid == TIME_ZONE_ID_STANDARD ? tzinfo.StandardBias :
607       ( tzid == TIME_ZONE_ID_DAYLIGHT ? tzinfo.DaylightBias : 0 ));
608   buf->dstflag = (tzid == TIME_ZONE_ID_DAYLIGHT?1:0);
609 }
610
611 /*********************************************************************
612  *              _ftime64_s (MSVCRT.@)
613  */
614 int CDECL MSVCRT__ftime64_s(struct MSVCRT___timeb64 *buf)
615 {
616     if( !MSVCRT_CHECK_PMT( buf != NULL ) )
617     {
618         *MSVCRT__errno() = MSVCRT_EINVAL;
619         return MSVCRT_EINVAL;
620     }
621     MSVCRT__ftime64(buf);
622     return 0;
623 }
624
625 /*********************************************************************
626  *              _ftime32 (MSVCRT.@)
627  */
628 void CDECL MSVCRT__ftime32(struct MSVCRT___timeb32 *buf)
629 {
630     struct MSVCRT___timeb64 buf64;
631
632     MSVCRT__ftime64( &buf64 );
633     buf->time     = buf64.time;
634     buf->millitm  = buf64.millitm;
635     buf->timezone = buf64.timezone;
636     buf->dstflag  = buf64.dstflag;
637 }
638
639 /*********************************************************************
640  *              _ftime32_s (MSVCRT.@)
641  */
642 int CDECL MSVCRT__ftime32_s(struct MSVCRT___timeb32 *buf)
643 {
644     if( !MSVCRT_CHECK_PMT( buf != NULL ) )
645     {
646         *MSVCRT__errno() = MSVCRT_EINVAL;
647         return MSVCRT_EINVAL;
648     }
649     MSVCRT__ftime32(buf);
650     return 0;
651 }
652
653 /*********************************************************************
654  *              _ftime (MSVCRT.@)
655  */
656 #ifdef _WIN64
657 void CDECL MSVCRT__ftime(struct MSVCRT___timeb64 *buf)
658 {
659     MSVCRT__ftime64( buf );
660 }
661 #else
662 void CDECL MSVCRT__ftime(struct MSVCRT___timeb32 *buf)
663 {
664     MSVCRT__ftime32( buf );
665 }
666 #endif
667
668 /*********************************************************************
669  *              _time64 (MSVCRT.@)
670  */
671 MSVCRT___time64_t CDECL MSVCRT__time64(MSVCRT___time64_t *buf)
672 {
673     MSVCRT___time64_t curtime;
674     struct MSVCRT___timeb64 tb;
675
676     MSVCRT__ftime64(&tb);
677
678     curtime = tb.time;
679     return buf ? *buf = curtime : curtime;
680 }
681
682 /*********************************************************************
683  *              _time32 (MSVCRT.@)
684  */
685 MSVCRT___time32_t CDECL MSVCRT__time32(MSVCRT___time32_t *buf)
686 {
687     MSVCRT___time32_t curtime;
688     struct MSVCRT___timeb64 tb;
689
690     MSVCRT__ftime64(&tb);
691
692     curtime = tb.time;
693     return buf ? *buf = curtime : curtime;
694 }
695
696 /*********************************************************************
697  *              time (MSVCRT.@)
698  */
699 #ifdef _WIN64
700 MSVCRT___time64_t CDECL MSVCRT_time(MSVCRT___time64_t* buf)
701 {
702     return MSVCRT__time64( buf );
703 }
704 #else
705 MSVCRT___time32_t CDECL MSVCRT_time(MSVCRT___time32_t* buf)
706 {
707     return MSVCRT__time32( buf );
708 }
709 #endif
710
711 /*********************************************************************
712  *              _daylight (MSVCRT.@)
713  */
714 int MSVCRT___daylight = 0;
715
716 /*********************************************************************
717  *              __p_daylight (MSVCRT.@)
718  */
719 int * CDECL MSVCRT___p__daylight(void)
720 {
721         return &MSVCRT___daylight;
722 }
723
724 /*********************************************************************
725  *              _dstbias (MSVCRT.@)
726  */
727 int MSVCRT__dstbias = 0;
728
729 /*********************************************************************
730  *              __p_dstbias (MSVCRT.@)
731  */
732 int * CDECL __p__dstbias(void)
733 {
734     return &MSVCRT__dstbias;
735 }
736
737 /*********************************************************************
738  *              _timezone (MSVCRT.@)
739  */
740 MSVCRT_long MSVCRT___timezone = 0;
741
742 /*********************************************************************
743  *              __p_timezone (MSVCRT.@)
744  */
745 MSVCRT_long * CDECL MSVCRT___p__timezone(void)
746 {
747         return &MSVCRT___timezone;
748 }
749
750 /*********************************************************************
751  *              _tzname (MSVCRT.@)
752  * NOTES
753  *  Some apps (notably Mozilla) insist on writing to these, so the buffer
754  *  must be large enough.  The size is picked based on observation of
755  *  Windows XP.
756  */
757 static char tzname_std[64] = "PST";
758 static char tzname_dst[64] = "PDT";
759 char *MSVCRT__tzname[2] = { tzname_std, tzname_dst };
760
761 /*********************************************************************
762  *              _get_tzname (MSVCRT.@)
763  */
764 int CDECL MSVCRT__get_tzname(MSVCRT_size_t *ret, char *buf, MSVCRT_size_t bufsize, int index)
765 {
766     char *timezone;
767
768     switch(index)
769     {
770     case 0:
771         timezone = tzname_std;
772         break;
773     case 1:
774         timezone = tzname_dst;
775         break;
776     default:
777         *MSVCRT__errno() = MSVCRT_EINVAL;
778         return MSVCRT_EINVAL;
779     }
780
781     if(!ret || (!buf && bufsize > 0) || (buf && !bufsize))
782     {
783         *MSVCRT__errno() = MSVCRT_EINVAL;
784         return MSVCRT_EINVAL;
785     }
786
787     *ret = strlen(timezone)+1;
788     if(!buf && !bufsize)
789         return 0;
790
791     strcpy(buf, timezone);
792     return 0;
793 }
794
795 /*********************************************************************
796  *              __p_tzname (MSVCRT.@)
797  */
798 char ** CDECL __p__tzname(void)
799 {
800         return MSVCRT__tzname;
801 }
802
803 /*********************************************************************
804  *              _tzset (MSVCRT.@)
805  */
806 void CDECL MSVCRT__tzset(void)
807 {
808     tzset();
809 #if defined(HAVE_TIMEZONE) && defined(HAVE_DAYLIGHT)
810     MSVCRT___daylight = daylight;
811     MSVCRT___timezone = timezone;
812 #else
813     {
814         static const time_t seconds_in_year = (365 * 24 + 6) * 3600;
815         time_t t;
816         struct tm *tmp;
817         int zone_january, zone_july;
818
819         _mlock(_TIME_LOCK);
820         t = (time(NULL) / seconds_in_year) * seconds_in_year;
821         tmp = localtime(&t);
822         zone_january = -tmp->tm_gmtoff;
823         t += seconds_in_year / 2;
824         tmp = localtime(&t);
825         zone_july = -tmp->tm_gmtoff;
826         _munlock(_TIME_LOCK);
827
828         MSVCRT___daylight = (zone_january != zone_july);
829         MSVCRT___timezone = max(zone_january, zone_july);
830     }
831 #endif
832     lstrcpynA(tzname_std, tzname[0], sizeof(tzname_std));
833     tzname_std[sizeof(tzname_std) - 1] = '\0';
834     lstrcpynA(tzname_dst, tzname[1], sizeof(tzname_dst));
835     tzname_dst[sizeof(tzname_dst) - 1] = '\0';
836 }
837
838 static inline BOOL strftime_date(char *str, MSVCRT_size_t *pos, MSVCRT_size_t max,
839         BOOL alternate, const struct MSVCRT_tm *mstm, MSVCRT___lc_time_data *time_data)
840 {
841     char *format;
842     SYSTEMTIME st;
843     MSVCRT_size_t ret;
844
845     st.wYear = mstm->tm_year + 1900;
846     st.wMonth = mstm->tm_mon + 1;
847     st.wDayOfWeek = mstm->tm_wday;
848     st.wDay = mstm->tm_mday;
849     st.wHour = mstm->tm_hour;
850     st.wMinute = mstm->tm_min;
851     st.wSecond = mstm->tm_sec;
852     st.wMilliseconds = 0;
853
854     format = alternate ? time_data->str.names.date : time_data->str.names.short_date;
855     ret = GetDateFormatA(time_data->lcid, 0, &st, format, NULL, 0);
856     if(ret && ret<max-*pos)
857         ret = GetDateFormatA(time_data->lcid, 0, &st, format, str+*pos, max-*pos);
858     if(!ret) {
859         *str = 0;
860         *MSVCRT__errno() = MSVCRT_EINVAL;
861         return FALSE;
862     }else if(ret > max-*pos) {
863         *str = 0;
864         *MSVCRT__errno() = MSVCRT_ERANGE;
865         return FALSE;
866     }
867     *pos += ret-1;
868     return TRUE;
869 }
870
871 static inline BOOL strftime_time(char *str, MSVCRT_size_t *pos, MSVCRT_size_t max,
872         const struct MSVCRT_tm *mstm, MSVCRT___lc_time_data *time_data)
873 {
874     SYSTEMTIME st;
875     MSVCRT_size_t ret;
876
877     st.wYear = mstm->tm_year + 1900;
878     st.wMonth = mstm->tm_mon + 1;
879     st.wDayOfWeek = mstm->tm_wday;
880     st.wDay = mstm->tm_mday;
881     st.wHour = mstm->tm_hour;
882     st.wMinute = mstm->tm_min;
883     st.wSecond = mstm->tm_sec;
884     st.wMilliseconds = 0;
885
886     ret = GetTimeFormatA(time_data->lcid, 0, &st, time_data->str.names.time, NULL, 0);
887     if(ret && ret<max-*pos)
888         ret = GetTimeFormatA(time_data->lcid, 0, &st, time_data->str.names.time,
889                 str+*pos, max-*pos);
890     if(!ret) {
891         *str = 0;
892         *MSVCRT__errno() = MSVCRT_EINVAL;
893         return FALSE;
894     }else if(ret > max-*pos) {
895         *str = 0;
896         *MSVCRT__errno() = MSVCRT_ERANGE;
897         return FALSE;
898     }
899     *pos += ret-1;
900     return TRUE;
901 }
902
903 static inline BOOL strftime_str(char *str, MSVCRT_size_t *pos, MSVCRT_size_t max, char *src)
904 {
905     MSVCRT_size_t len = strlen(src);
906     if(len > max-*pos) {
907         *str = 0;
908         *MSVCRT__errno() = MSVCRT_ERANGE;
909         return FALSE;
910     }
911
912     memcpy(str+*pos, src, len);
913     *pos += len;
914     return TRUE;
915 }
916
917 static inline BOOL strftime_int(char *str, MSVCRT_size_t *pos, MSVCRT_size_t max,
918         int src, int prec, int l, int h)
919 {
920     MSVCRT_size_t len;
921
922     if(src<l || src>h) {
923         *str = 0;
924         *MSVCRT__errno() = MSVCRT_EINVAL;
925         return FALSE;
926     }
927
928     len = MSVCRT__snprintf(str+*pos, max-*pos, "%0*d", prec, src);
929     if(len == -1) {
930         *str = 0;
931         *MSVCRT__errno() = MSVCRT_ERANGE;
932         return FALSE;
933     }
934
935     *pos += len;
936     return TRUE;
937 }
938
939 /*********************************************************************
940  *              _Strftime (MSVCRT.@)
941  */
942 MSVCRT_size_t CDECL _Strftime(char *str, MSVCRT_size_t max, const char *format,
943         const struct MSVCRT_tm *mstm, MSVCRT___lc_time_data *time_data)
944 {
945     MSVCRT_size_t ret, tmp;
946     BOOL alternate;
947
948     TRACE("(%p %ld %s %p %p)\n", str, max, format, mstm, time_data);
949
950     if(!str || !format) {
951         if(str && max)
952             *str = 0;
953         *MSVCRT__errno() = MSVCRT_EINVAL;
954         return 0;
955     }
956
957     if(!time_data)
958         time_data = get_locinfo()->lc_time_curr;
959
960     for(ret=0; *format && ret<max; format++) {
961         if(*format != '%') {
962             str[ret++] = *format;
963             continue;
964         }
965
966         format++;
967         if(*format == '#') {
968             alternate = TRUE;
969             format++;
970         }else {
971             alternate = FALSE;
972         }
973
974         if(!mstm)
975             goto einval_error;
976
977         switch(*format) {
978         case 'c':
979             if(!strftime_date(str, &ret, max, alternate, mstm, time_data))
980                 return 0;
981             if(ret < max)
982                 str[ret++] = ' ';
983             if(!strftime_time(str, &ret, max, mstm, time_data))
984                 return 0;
985             break;
986         case 'x':
987             if(!strftime_date(str, &ret, max, alternate, mstm, time_data))
988                 return 0;
989             break;
990         case 'X':
991             if(!strftime_time(str, &ret, max, mstm, time_data))
992                 return 0;
993             break;
994         case 'a':
995             if(mstm->tm_wday<0 || mstm->tm_wday>6)
996                 goto einval_error;
997             if(!strftime_str(str, &ret, max, time_data->str.names.short_wday[mstm->tm_wday]))
998                 return 0;
999             break;
1000         case 'A':
1001             if(mstm->tm_wday<0 || mstm->tm_wday>6)
1002                 goto einval_error;
1003             if(!strftime_str(str, &ret, max, time_data->str.names.wday[mstm->tm_wday]))
1004                 return 0;
1005             break;
1006         case 'b':
1007             if(mstm->tm_mon<0 || mstm->tm_mon>11)
1008                 goto einval_error;
1009             if(!strftime_str(str, &ret, max, time_data->str.names.short_mon[mstm->tm_mon]))
1010                 return 0;
1011             break;
1012         case 'B':
1013             if(mstm->tm_mon<0 || mstm->tm_mon>11)
1014                 goto einval_error;
1015             if(!strftime_str(str, &ret, max, time_data->str.names.mon[mstm->tm_mon]))
1016                 return 0;
1017             break;
1018         case 'd':
1019             if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 0, 31))
1020                 return 0;
1021             break;
1022         case 'H':
1023             if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23))
1024                 return 0;
1025             break;
1026         case 'I':
1027             tmp = mstm->tm_hour;
1028             if(tmp > 12)
1029                 tmp -= 12;
1030             else if(!tmp)
1031                 tmp = 12;
1032             if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 2, 1, 12))
1033                 return 0;
1034             break;
1035         case 'j':
1036             if(!strftime_int(str, &ret, max, mstm->tm_yday+1, alternate ? 0 : 3, 1, 366))
1037                 return 0;
1038             break;
1039         case 'm':
1040             if(!strftime_int(str, &ret, max, mstm->tm_mon+1, alternate ? 0 : 2, 1, 12))
1041                 return 0;
1042             break;
1043         case 'M':
1044             if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59))
1045                 return 0;
1046             break;
1047         case 'p':
1048             if(mstm->tm_hour<0 || mstm->tm_hour>23)
1049                 goto einval_error;
1050             if(!strftime_str(str, &ret, max, mstm->tm_hour<12 ?
1051                         time_data->str.names.am : time_data->str.names.pm))
1052                 return 0;
1053             break;
1054         case 'S':
1055             if(!strftime_int(str, &ret, max, mstm->tm_sec, alternate ? 0 : 2, 0, 59))
1056                 return 0;
1057             break;
1058         case 'w':
1059             if(!strftime_int(str, &ret, max, mstm->tm_wday, 0, 0, 6))
1060                 return 0;
1061             break;
1062         case 'y':
1063             if(!strftime_int(str, &ret, max, mstm->tm_year%100, alternate ? 0 : 2, 0, 99))
1064                 return 0;
1065             break;
1066         case 'Y':
1067             tmp = 1900+mstm->tm_year;
1068             if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 4, 0, 9999))
1069                 return 0;
1070             break;
1071         case 'z':
1072         case 'Z':
1073             MSVCRT__tzset();
1074             if(MSVCRT__get_tzname(&tmp, str+ret, max-ret, mstm->tm_isdst ? 1 : 0))
1075                 return 0;
1076             ret += tmp;
1077             break;
1078         case 'U':
1079         case 'W':
1080             if(mstm->tm_wday<0 || mstm->tm_wday>6 || mstm->tm_yday<0 || mstm->tm_yday>365)
1081                 goto einval_error;
1082             if(*format == 'U')
1083                 tmp = mstm->tm_wday;
1084             else if(!mstm->tm_wday)
1085                 tmp = 6;
1086             else
1087                 tmp = mstm->tm_wday-1;
1088
1089             tmp = mstm->tm_yday/7 + (tmp<=mstm->tm_yday%7);
1090             if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 2, 0, 53))
1091                 return 0;
1092             break;
1093         case '%':
1094             str[ret++] = '%';
1095             break;
1096         default:
1097             WARN("unknown format %c\n", *format);
1098             goto einval_error;
1099         }
1100     }
1101
1102     if(ret == max) {
1103         if(max)
1104             *str = 0;
1105         *MSVCRT__errno() = MSVCRT_ERANGE;
1106         return 0;
1107     }
1108
1109     str[ret] = 0;
1110     return ret;
1111
1112 einval_error:
1113     *str = 0;
1114     *MSVCRT__errno() = MSVCRT_EINVAL;
1115     return 0;
1116 }
1117
1118 /*********************************************************************
1119  *              strftime (MSVCRT.@)
1120  */
1121 MSVCRT_size_t CDECL MSVCRT_strftime( char *str, MSVCRT_size_t max, const char *format,
1122                                      const struct MSVCRT_tm *mstm )
1123 {
1124     return _Strftime(str, max, format, mstm, NULL);
1125 }
1126
1127 /*********************************************************************
1128  *              wcsftime (MSVCRT.@)
1129  */
1130 MSVCRT_size_t CDECL MSVCRT_wcsftime( MSVCRT_wchar_t *str, MSVCRT_size_t max,
1131                                      const MSVCRT_wchar_t *format, const struct MSVCRT_tm *mstm )
1132 {
1133     char *s, *fmt;
1134     MSVCRT_size_t len;
1135
1136     TRACE("%p %ld %s %p\n", str, max, debugstr_w(format), mstm );
1137
1138     len = WideCharToMultiByte( CP_UNIXCP, 0, format, -1, NULL, 0, NULL, NULL );
1139     if (!(fmt = MSVCRT_malloc( len ))) return 0;
1140     WideCharToMultiByte( CP_UNIXCP, 0, format, -1, fmt, len, NULL, NULL );
1141
1142     if ((s = MSVCRT_malloc( max*4 )))
1143     {
1144         if (!MSVCRT_strftime( s, max*4, fmt, mstm )) s[0] = 0;
1145         len = MultiByteToWideChar( CP_UNIXCP, 0, s, -1, str, max );
1146         if (len) len--;
1147         MSVCRT_free( s );
1148     }
1149     else len = 0;
1150
1151     MSVCRT_free( fmt );
1152     return len;
1153 }
1154
1155 static char* asctime_buf(char *buf, const struct MSVCRT_tm *mstm)
1156 {
1157     static const char wday[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
1158     static const char month[12][4] = {"Jan", "Feb", "Mar", "Apr", "May",
1159         "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1160
1161     if (mstm->tm_sec<0 || mstm->tm_sec>59
1162             || mstm->tm_min<0 || mstm->tm_min>59
1163             || mstm->tm_hour<0 || mstm->tm_hour>23
1164             || mstm->tm_mon<0 || mstm->tm_mon>11
1165             || mstm->tm_wday<0 || mstm->tm_wday>6
1166             || mstm->tm_year<0 || mstm->tm_mday<0
1167             || mstm->tm_mday>MonthLengths[IsLeapYear(1900+mstm->tm_year)][mstm->tm_mon]) {
1168         *MSVCRT__errno() = MSVCRT_EINVAL;
1169         return NULL;
1170     }
1171
1172     MSVCRT__snprintf(buf, 26, "%s %s %02d %02d:%02d:%02d %c%03d\n", wday[mstm->tm_wday],
1173             month[mstm->tm_mon], mstm->tm_mday, mstm->tm_hour, mstm->tm_min,
1174             mstm->tm_sec, '1'+(mstm->tm_year+900)/1000, (900+mstm->tm_year)%1000);
1175     return buf;
1176 }
1177
1178 /*********************************************************************
1179  *              asctime (MSVCRT.@)
1180  */
1181 char * CDECL MSVCRT_asctime(const struct MSVCRT_tm *mstm)
1182 {
1183     thread_data_t *data = msvcrt_get_thread_data();
1184
1185     /* asctime returns date in format that always has exactly 26 characters */
1186     if (!data->asctime_buffer) {
1187         data->asctime_buffer = MSVCRT_malloc(26);
1188         if (!data->asctime_buffer) {
1189             *MSVCRT__errno() = MSVCRT_ENOMEM;
1190             return NULL;
1191         }
1192     }
1193
1194     return asctime_buf(data->asctime_buffer, mstm);
1195 }
1196
1197 /*********************************************************************
1198  *      asctime_s (MSVCRT.@)
1199  */
1200 int CDECL MSVCRT_asctime_s(char* time, MSVCRT_size_t size, const struct MSVCRT_tm *mstm)
1201 {
1202     if (!MSVCRT_CHECK_PMT(time != NULL)
1203             || !MSVCRT_CHECK_PMT(mstm != NULL)
1204             || !MSVCRT_CHECK_PMT(size >= 26)) {
1205         if (time && size)
1206             time[0] = 0;
1207         *MSVCRT__errno() = MSVCRT_EINVAL;
1208         return MSVCRT_EINVAL;
1209     }
1210
1211     if (!MSVCRT_CHECK_PMT(mstm->tm_sec>=0) || !MSVCRT_CHECK_PMT(mstm->tm_sec<60)
1212             || !MSVCRT_CHECK_PMT(mstm->tm_min>=0) || !MSVCRT_CHECK_PMT(mstm->tm_min<60)
1213             || !MSVCRT_CHECK_PMT(mstm->tm_hour>=0) || !MSVCRT_CHECK_PMT(mstm->tm_hour<24)
1214             || !MSVCRT_CHECK_PMT(mstm->tm_mon>=0) || !MSVCRT_CHECK_PMT(mstm->tm_mon<12)
1215             || !MSVCRT_CHECK_PMT(mstm->tm_wday>=0) || !MSVCRT_CHECK_PMT(mstm->tm_wday<7)
1216             || !MSVCRT_CHECK_PMT(mstm->tm_year>=0) || !MSVCRT_CHECK_PMT(mstm->tm_mday>=0)
1217             || !MSVCRT_CHECK_PMT(mstm->tm_mday <= MonthLengths[IsLeapYear(1900+mstm->tm_year)][mstm->tm_mon])) {
1218         *MSVCRT__errno() = MSVCRT_EINVAL;
1219         return MSVCRT_EINVAL;
1220     }
1221
1222     asctime_buf(time, mstm);
1223     return 0;
1224 }
1225
1226 /*********************************************************************
1227  *              _wasctime (MSVCRT.@)
1228  */
1229 MSVCRT_wchar_t * CDECL MSVCRT__wasctime(const struct MSVCRT_tm *mstm)
1230 {
1231     thread_data_t *data = msvcrt_get_thread_data();
1232     char buffer[26];
1233
1234     if(!data->wasctime_buffer) {
1235         data->wasctime_buffer = MSVCRT_malloc(26*sizeof(MSVCRT_wchar_t));
1236         if(!data->wasctime_buffer) {
1237             *MSVCRT__errno() = MSVCRT_ENOMEM;
1238             return NULL;
1239         }
1240     }
1241
1242     if(!asctime_buf(buffer, mstm))
1243         return NULL;
1244
1245     MultiByteToWideChar(CP_ACP, 0, buffer, -1, data->wasctime_buffer, 26);
1246     return data->wasctime_buffer;
1247 }
1248
1249 /*********************************************************************
1250  *      _wasctime_s (MSVCRT.@)
1251  */
1252 int CDECL MSVCRT__wasctime_s(MSVCRT_wchar_t* time, MSVCRT_size_t size, const struct MSVCRT_tm *mstm)
1253 {
1254     char buffer[26];
1255     int ret;
1256
1257     if(!MSVCRT_CHECK_PMT(time != NULL)
1258             || !MSVCRT_CHECK_PMT(mstm != NULL)
1259             || !MSVCRT_CHECK_PMT(size >= 26)) {
1260         if(time && size)
1261             time[0] = 0;
1262         *MSVCRT__errno() = MSVCRT_EINVAL;
1263         return MSVCRT_EINVAL;
1264     }
1265
1266     ret = MSVCRT_asctime_s(buffer, sizeof(buffer), mstm);
1267     if(!ret)
1268         return ret;
1269     MultiByteToWideChar(CP_ACP, 0, buffer, -1, time, size);
1270     return 0;
1271 }
1272
1273 /*********************************************************************
1274  *              _ctime64 (MSVCRT.@)
1275  */
1276 char * CDECL MSVCRT__ctime64(const MSVCRT___time64_t *time)
1277 {
1278     struct MSVCRT_tm *t;
1279     t = MSVCRT__localtime64( time );
1280     if (!t) return NULL;
1281     return MSVCRT_asctime( t );
1282 }
1283
1284 /*********************************************************************
1285  *              _ctime64_s (MSVCRT.@)
1286  */
1287 int CDECL MSVCRT__ctime64_s(char *res, MSVCRT_size_t len, const MSVCRT___time64_t *time)
1288 {
1289     struct MSVCRT_tm *t;
1290     if( !MSVCRT_CHECK_PMT( res != NULL ) || !MSVCRT_CHECK_PMT( len >= 26 ) )
1291     {
1292         *MSVCRT__errno() = MSVCRT_EINVAL;
1293         return MSVCRT_EINVAL;
1294     }
1295     res[0] = '\0';
1296     if( !MSVCRT_CHECK_PMT( time != NULL ) || !MSVCRT_CHECK_PMT( *time > 0 ) )
1297     {
1298         *MSVCRT__errno() = MSVCRT_EINVAL;
1299         return MSVCRT_EINVAL;
1300     }
1301     t = MSVCRT__localtime64( time );
1302     strcpy( res, MSVCRT_asctime( t ) );
1303     return 0;
1304 }
1305
1306 /*********************************************************************
1307  *              _ctime32 (MSVCRT.@)
1308  */
1309 char * CDECL MSVCRT__ctime32(const MSVCRT___time32_t *time)
1310 {
1311     struct MSVCRT_tm *t;
1312     t = MSVCRT__localtime32( time );
1313     if (!t) return NULL;
1314     return MSVCRT_asctime( t );
1315 }
1316
1317 /*********************************************************************
1318  *              _ctime32_s (MSVCRT.@)
1319  */
1320 int CDECL MSVCRT__ctime32_s(char *res, MSVCRT_size_t len, const MSVCRT___time32_t *time)
1321 {
1322     struct MSVCRT_tm *t;
1323     if( !MSVCRT_CHECK_PMT( res != NULL ) || !MSVCRT_CHECK_PMT( len >= 26 ) )
1324     {
1325         *MSVCRT__errno() = MSVCRT_EINVAL;
1326         return MSVCRT_EINVAL;
1327     }
1328     res[0] = '\0';
1329     if( !MSVCRT_CHECK_PMT( time != NULL ) || !MSVCRT_CHECK_PMT( *time > 0 ) )
1330     {
1331         *MSVCRT__errno() = MSVCRT_EINVAL;
1332         return MSVCRT_EINVAL;
1333     }
1334     t = MSVCRT__localtime32( time );
1335     strcpy( res, MSVCRT_asctime( t ) );
1336     return 0;
1337 }
1338
1339 /*********************************************************************
1340  *              ctime (MSVCRT.@)
1341  */
1342 #ifdef _WIN64
1343 char * CDECL MSVCRT_ctime(const MSVCRT___time64_t *time)
1344 {
1345     return MSVCRT__ctime64( time );
1346 }
1347 #else
1348 char * CDECL MSVCRT_ctime(const MSVCRT___time32_t *time)
1349 {
1350     return MSVCRT__ctime32( time );
1351 }
1352 #endif
1353
1354 /*********************************************************************
1355  *              _wctime64 (MSVCRT.@)
1356  */
1357 MSVCRT_wchar_t * CDECL MSVCRT__wctime64(const MSVCRT___time64_t *time)
1358 {
1359     return MSVCRT__wasctime( MSVCRT__localtime64(time) );
1360 }
1361
1362 /*********************************************************************
1363  *              _wctime32 (MSVCRT.@)
1364  */
1365 MSVCRT_wchar_t * CDECL MSVCRT__wctime32(const MSVCRT___time32_t *time)
1366 {
1367     return MSVCRT__wasctime( MSVCRT__localtime32(time) );
1368 }
1369
1370 /*********************************************************************
1371  *              _wctime (MSVCRT.@)
1372  */
1373 #ifdef _WIN64
1374 MSVCRT_wchar_t * CDECL MSVCRT__wctime(const MSVCRT___time64_t *time)
1375 {
1376     return MSVCRT__wctime64( time );
1377 }
1378 #else
1379 MSVCRT_wchar_t * CDECL MSVCRT__wctime(const MSVCRT___time32_t *time)
1380 {
1381     return MSVCRT__wctime32( time );
1382 }
1383 #endif