ReactOS 0.4.16-dev-2104-gb84fa49
time.c File Reference
#include <locale.h>
#include <stdlib.h>
#include <time.h>
#include <sys/timeb.h>
#include "msvcrt.h"
#include "mtdll.h"
#include "winbase.h"
#include "winnls.h"
#include "winternl.h"
#include "wine/debug.h"
Include dependency graph for time.c:

Go to the source code of this file.

Macros

#define MIN_GMTIME64_TIME   0
 
#define MAX_GMTIME64_TIME   _MAX__TIME64_T
 
#define SECSPERDAY   86400
 
#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)
 
#define STRFTIME_CHAR   char
 
#define STRFTIME_TD(td, name)   td->str.names.name
 
#define strftime_str(a, b, c, d)   strftime_nstr(a,b,c,d,SIZE_MAX)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msvcrt)
 
void msvcrt_init_clock (void)
 
static BOOL IsLeapYear (int Year)
 
static void write_invalid_msvcrt_tm (struct tm *tm)
 
void CDECL _tzset (void)
 
static void _tzset_init (void)
 
static BOOL is_dst (const SYSTEMTIME *st)
 
static __time64_t mktime_helper (struct tm *mstm, BOOL local)
 
__time64_t CDECL _mktime64 (struct tm *mstm)
 
__time32_t CDECL _mktime32 (struct tm *mstm)
 
__time64_t CDECL _mkgmtime64 (struct tm *time)
 
__time32_t CDECL _mkgmtime32 (struct tm *time)
 
int CDECL _localtime64_s (struct tm *res, const __time64_t *secs)
 
struct tm *CDECL _localtime64 (const __time64_t *secs)
 
struct tm *CDECL _localtime32 (const __time32_t *secs)
 
int CDECL _localtime32_s (struct tm *time, const __time32_t *secs)
 
int CDECL _gmtime64_s (struct tm *res, const __time64_t *secs)
 
struct tm *CDECL _gmtime64 (const __time64_t *secs)
 
int CDECL _gmtime32_s (struct tm *res, const __time32_t *secs)
 
struct tm *CDECL _gmtime32 (const __time32_t *secs)
 
char *CDECL _strdate (char *date)
 
int CDECL _strdate_s (char *date, size_t size)
 
wchar_t *CDECL _wstrdate (wchar_t *date)
 
int CDECL _wstrdate_s (wchar_t *date, size_t size)
 
char *CDECL _strtime (char *time)
 
int CDECL _strtime_s (char *time, size_t size)
 
wchar_t *CDECL _wstrtime (wchar_t *time)
 
int CDECL _wstrtime_s (wchar_t *time, size_t size)
 
clock_t CDECL clock (void)
 
double CDECL _difftime64 (__time64_t time1, __time64_t time2)
 
double CDECL _difftime32 (__time32_t time1, __time32_t time2)
 
void CDECL _ftime64 (struct __timeb64 *buf)
 
int CDECL _ftime64_s (struct __timeb64 *buf)
 
void CDECL _ftime32 (struct __timeb32 *buf)
 
int CDECL _ftime32_s (struct __timeb32 *buf)
 
__time64_t CDECL _time64 (__time64_t *buf)
 
__time32_t CDECL _time32 (__time32_t *buf)
 
int *CDECL __p__daylight (void)
 
__msvcrt_long *CDECL __p__dstbias (void)
 
__msvcrt_long *CDECL __p__timezone (void)
 
int CDECL _get_tzname (size_t *ret, char *buf, size_t bufsize, int index)
 
char **CDECL __p__tzname (void)
 
static BOOL strftime_nstr (STRFTIME_CHAR *str, size_t *pos, size_t max, const STRFTIME_CHAR *src, size_t len)
 
static BOOL strftime_int (STRFTIME_CHAR *str, size_t *pos, size_t max, int src, int prec, int l, int h)
 
static BOOL strftime_format (STRFTIME_CHAR *str, size_t *pos, size_t max, const struct tm *mstm, __lc_time_data *time_data, const STRFTIME_CHAR *format)
 
static size_t strftime_impl (STRFTIME_CHAR *str, size_t max, const STRFTIME_CHAR *format, const struct tm *mstm, __lc_time_data *time_data, _locale_t loc)
 
static size_t strftime_helper (char *str, size_t max, const char *format, const struct tm *mstm, __lc_time_data *time_data, _locale_t loc)
 
size_t CDECL _Strftime (char *str, size_t max, const char *format, const struct tm *mstm, void *time_data)
 
size_t CDECL strftime (char *str, size_t max, const char *format, const struct tm *mstm)
 
static size_t wcsftime_helper (wchar_t *str, size_t max, const wchar_t *format, const struct tm *mstm, __lc_time_data *time_data, _locale_t loc)
 
size_t CDECL _wcsftime_l (wchar_t *str, size_t max, const wchar_t *format, const struct tm *mstm, _locale_t loc)
 
size_t CDECL wcsftime (wchar_t *str, size_t max, const wchar_t *format, const struct tm *mstm)
 
static charasctime_buf (char *buf, const struct tm *mstm)
 
char *CDECL asctime (const struct tm *mstm)
 
int CDECL asctime_s (char *time, size_t size, const struct tm *mstm)
 
wchar_t *CDECL _wasctime (const struct tm *mstm)
 
int CDECL _wasctime_s (wchar_t *time, size_t size, const struct tm *mstm)
 
char *CDECL _ctime64 (const __time64_t *time)
 
errno_t CDECL _ctime64_s (char *res, size_t len, const __time64_t *time)
 
char *CDECL _ctime32 (const __time32_t *time)
 
errno_t CDECL _ctime32_s (char *res, size_t len, const __time32_t *time)
 
wchar_t *CDECL _wctime64 (const __time64_t *time)
 
wchar_t *CDECL _wctime32 (const __time32_t *time)
 
int CDECL _wctime64_s (wchar_t *buf, size_t size, const __time64_t *time)
 
int CDECL _wctime32_s (wchar_t *buf, size_t size, const __time32_t *time)
 

Variables

static LONGLONG init_time
 
static const int MonthLengths [2][12]
 
static const int MAX_SECONDS = 59
 
int MSVCRT___daylight = 1
 
__msvcrt_long MSVCRT___timezone = 28800
 
__msvcrt_long MSVCRT__dstbias = -3600
 
static char tzname_std [64] = "PST"
 
static char tzname_dst [64] = "PDT"
 
charMSVCRT__tzname [2] = { tzname_std, tzname_dst }
 
static TIME_ZONE_INFORMATION tzi = {0}
 

Macro Definition Documentation

◆ MAX_GMTIME64_TIME

#define MAX_GMTIME64_TIME   _MAX__TIME64_T

Definition at line 71 of file time.c.

◆ MIN_GMTIME64_TIME

#define MIN_GMTIME64_TIME   0

Definition at line 70 of file time.c.

◆ SECS_1601_TO_1970

#define SECS_1601_TO_1970   ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)

Definition at line 235 of file time.c.

◆ SECSPERDAY

#define SECSPERDAY   86400

Definition at line 233 of file time.c.

◆ STRFTIME_CHAR

#define STRFTIME_CHAR   char

Definition at line 889 of file time.c.

◆ strftime_str

#define strftime_str (   a,
  b,
  c,
  d 
)    strftime_nstr(a,b,c,d,SIZE_MAX)

Definition at line 896 of file time.c.

◆ STRFTIME_TD

#define STRFTIME_TD (   td,
  name 
)    td->str.names.name

Definition at line 890 of file time.c.

◆ TICKS_1601_TO_1970

#define TICKS_1601_TO_1970   (SECS_1601_TO_1970 * TICKSPERSEC)

Definition at line 238 of file time.c.

◆ TICKSPERMSEC

#define TICKSPERMSEC   10000

Definition at line 237 of file time.c.

◆ TICKSPERSEC

#define TICKSPERSEC   10000000

Definition at line 236 of file time.c.

Function Documentation

◆ __p__daylight()

int *CDECL __p__daylight ( void  )

Definition at line 808 of file time.c.

809{
810 return &MSVCRT___daylight;
811}
int MSVCRT___daylight
Definition: time.c:101

Referenced by Test__daylight().

◆ __p__dstbias()

__msvcrt_long *CDECL __p__dstbias ( void  )

Definition at line 816 of file time.c.

817{
818 return &MSVCRT__dstbias;
819}
__msvcrt_long MSVCRT__dstbias
Definition: time.c:111

Referenced by Test__dstbias().

◆ __p__timezone()

__msvcrt_long *CDECL __p__timezone ( void  )

Definition at line 836 of file time.c.

837{
838 return &MSVCRT___timezone;
839}
__msvcrt_long MSVCRT___timezone
Definition: time.c:106

Referenced by Test__timezone().

◆ __p__tzname()

char **CDECL __p__tzname ( void  )

Definition at line 883 of file time.c.

884{
885 return MSVCRT__tzname;
886}
char * MSVCRT__tzname[2]
Definition: time.c:121

Referenced by Test__tzname().

◆ _ctime32()

char *CDECL _ctime32 ( const __time32_t time)

Definition at line 1751 of file time.c.

1752{
1753 struct tm *t;
1754 t = _localtime32( time );
1755 if (!t) return NULL;
1756 return asctime( t );
1757}
#define NULL
Definition: types.h:112
char *CDECL asctime(const struct tm *mstm)
Definition: time.c:1636
struct tm *CDECL _localtime32(const __time32_t *secs)
Definition: time.c:430
GLdouble GLdouble t
Definition: gl.h:2047
__u16 time
Definition: mkdosfs.c:8

◆ _ctime32_s()

errno_t CDECL _ctime32_s ( char res,
size_t  len,
const __time32_t time 
)

Definition at line 1762 of file time.c.

1763{
1764 struct tm t;
1765 int ret;
1766
1767 if (!MSVCRT_CHECK_PMT( res != NULL )) return EINVAL;
1768 if (!MSVCRT_CHECK_PMT( len >= 26 )) return EINVAL;
1769 res[0] = '\0';
1770 if (!MSVCRT_CHECK_PMT( time != NULL )) return EINVAL;
1771 if (!MSVCRT_CHECK_PMT( *time > 0 )) return EINVAL;
1772
1773 ret = _localtime32_s( &t, time );
1774 if (ret)
1775 return ret;
1776 return asctime_s( res, len, &t );
1777}
#define EINVAL
Definition: errno.h:44
#define MSVCRT_CHECK_PMT(x)
Definition: msvcrt.h:378
int CDECL _localtime32_s(struct tm *time, const __time32_t *secs)
Definition: time.c:444
int CDECL asctime_s(char *time, size_t size, const struct tm *mstm)
Definition: time.c:1655
return ret
Definition: mutex.c:146
GLuint res
Definition: glext.h:9613
GLenum GLsizei len
Definition: glext.h:6722

◆ _ctime64()

char *CDECL _ctime64 ( const __time64_t time)

Definition at line 1720 of file time.c.

1721{
1722 struct tm *t;
1723 t = _localtime64( time );
1724 if (!t) return NULL;
1725 return asctime( t );
1726}
struct tm *CDECL _localtime64(const __time64_t *secs)
Definition: time.c:415

◆ _ctime64_s()

errno_t CDECL _ctime64_s ( char res,
size_t  len,
const __time64_t time 
)

Definition at line 1731 of file time.c.

1732{
1733 struct tm t;
1734 int ret;
1735
1736 if (!MSVCRT_CHECK_PMT( res != NULL )) return EINVAL;
1737 if (!MSVCRT_CHECK_PMT( len >= 26 )) return EINVAL;
1738 res[0] = '\0';
1739 if (!MSVCRT_CHECK_PMT( time != NULL )) return EINVAL;
1740 if (!MSVCRT_CHECK_PMT( *time > 0 )) return EINVAL;
1741
1742 ret = _localtime64_s( &t, time );
1743 if (ret)
1744 return ret;
1745 return asctime_s( res, len, &t );
1746}
int CDECL _localtime64_s(struct tm *res, const __time64_t *secs)
Definition: time.c:367

◆ _difftime32()

double CDECL _difftime32 ( __time32_t  time1,
__time32_t  time2 
)

Definition at line 717 of file time.c.

718{
719 return (double)(time1 - time2);
720}

◆ _difftime64()

double CDECL _difftime64 ( __time64_t  time1,
__time64_t  time2 
)

Definition at line 709 of file time.c.

710{
711 return (double)(time1 - time2);
712}

◆ _ftime32()

void CDECL _ftime32 ( struct __timeb32 buf)

Definition at line 756 of file time.c.

757{
758 struct __timeb64 buf64;
759
760 _ftime64( &buf64 );
761 buf->time = buf64.time;
762 buf->millitm = buf64.millitm;
763 buf->timezone = buf64.timezone;
764 buf->dstflag = buf64.dstflag;
765}
void CDECL _ftime64(struct __timeb64 *buf)
Definition: time.c:725
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751

Referenced by _ftime32_s().

◆ _ftime32_s()

int CDECL _ftime32_s ( struct __timeb32 buf)

Definition at line 770 of file time.c.

771{
772 if (!MSVCRT_CHECK_PMT( buf != NULL )) return EINVAL;
773 _ftime32(buf);
774 return 0;
775}
void CDECL _ftime32(struct __timeb32 *buf)
Definition: time.c:756

◆ _ftime64()

void CDECL _ftime64 ( struct __timeb64 buf)

Definition at line 725 of file time.c.

726{
728 FILETIME ft;
730
731 _tzset_init();
732
734
735 time = ((ULONGLONG)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
736
738 buf->millitm = (time % TICKSPERSEC) / TICKSPERMSEC;
739 buf->timezone = MSVCRT___timezone / 60;
740 buf->dstflag = GetTimeZoneInformation( &tzinfo) == TIME_ZONE_ID_DAYLIGHT;
741}
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
Definition: timezone.c:262
#define TICKSPERSEC
Definition: time.c:236
#define SECS_1601_TO_1970
Definition: time.c:235
static void _tzset_init(void)
Definition: time.c:182
#define TICKSPERMSEC
Definition: time.c:237
#define TIME_ZONE_ID_DAYLIGHT
Definition: rtltypes.h:254
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
uint64_t ULONGLONG
Definition: typedefs.h:67

Referenced by _ftime32(), _ftime64_s(), _time32(), and _time64().

◆ _ftime64_s()

int CDECL _ftime64_s ( struct __timeb64 buf)

Definition at line 746 of file time.c.

747{
748 if (!MSVCRT_CHECK_PMT( buf != NULL )) return EINVAL;
749 _ftime64(buf);
750 return 0;
751}

◆ _get_tzname()

int CDECL _get_tzname ( size_t ret,
char buf,
size_t  bufsize,
int  index 
)

Definition at line 844 of file time.c.

845{
846 char *timezone;
847
848 switch(index)
849 {
850 case 0:
852 break;
853 case 1:
855 break;
856 default:
857 *_errno() = EINVAL;
858 return EINVAL;
859 }
860
861 if(!ret || (!buf && bufsize > 0) || (buf && !bufsize))
862 {
863 *_errno() = EINVAL;
864 return EINVAL;
865 }
866
867 *ret = strlen(timezone)+1;
868 if(!buf && !bufsize)
869 return 0;
870 if(*ret > bufsize)
871 {
872 buf[0] = 0;
873 return ERANGE;
874 }
875
877 return 0;
878}
int *CDECL _errno(void)
Definition: errno.c:215
#define ERANGE
Definition: errno.h:55
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
static char tzname_std[64]
Definition: time.c:119
static char tzname_dst[64]
Definition: time.c:120
GLuint index
Definition: glext.h:6031
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
strcpy
Definition: string.h:131
Definition: fake.h:14

Referenced by _Strftime(), and strftime_impl().

◆ _gmtime32()

struct tm *CDECL _gmtime32 ( const __time32_t secs)

Definition at line 538 of file time.c.

539{
540 __time64_t secs64;
541
542 if(!secs)
543 return NULL;
544
545 secs64 = *secs;
546 return _gmtime64( &secs64 );
547}
struct tm *CDECL _gmtime64(const __time64_t *secs)
Definition: time.c:509
__int64 __time64_t
Definition: corecrt.h:619

◆ _gmtime32_s()

int CDECL _gmtime32_s ( struct tm res,
const __time32_t secs 
)

Definition at line 524 of file time.c.

525{
526 __time64_t secs64;
527
528 if(secs) {
529 secs64 = *secs;
530 return _gmtime64_s(res, &secs64);
531 }
532 return _gmtime64_s(res, NULL);
533}
int CDECL _gmtime64_s(struct tm *res, const __time64_t *secs)
Definition: time.c:464

◆ _gmtime64()

struct tm *CDECL _gmtime64 ( const __time64_t secs)

Definition at line 509 of file time.c.

510{
512
513 if(!data->time_buffer)
514 data->time_buffer = malloc(sizeof(struct tm));
515
516 if(_gmtime64_s(data->time_buffer, secs))
517 return NULL;
518 return data->time_buffer;
519}
#define malloc
Definition: debug_ros.c:4
thread_data_t *CDECL msvcrt_get_thread_data(void)
Definition: thread.c:45
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

Referenced by _gmtime32().

◆ _gmtime64_s()

int CDECL _gmtime64_s ( struct tm res,
const __time64_t secs 
)

Definition at line 464 of file time.c.

465{
466 int i;
467 FILETIME ft;
468 SYSTEMTIME st;
470
471 TRACE("res %p, secs %p (%I64d).\n", res, secs, secs ? *secs : 0);
472
473 if (!res || !secs || *secs < MIN_GMTIME64_TIME || *secs > MAX_GMTIME64_TIME) {
474 if (res) {
476 }
477
478 *_errno() = EINVAL;
479 return EINVAL;
480 }
481
483
484 ft.dwHighDateTime = (UINT)(time >> 32);
485 ft.dwLowDateTime = (UINT)time;
486
487 FileTimeToSystemTime(&ft, &st);
488
489 res->tm_sec = st.wSecond;
490 res->tm_min = st.wMinute;
491 res->tm_hour = st.wHour;
492 res->tm_mday = st.wDay;
493 res->tm_year = st.wYear - 1900;
494 res->tm_mon = st.wMonth - 1;
495 res->tm_wday = st.wDayOfWeek;
496 for (i = res->tm_yday = 0; i < st.wMonth - 1; i++) {
497 res->tm_yday += MonthLengths[IsLeapYear(st.wYear)][i];
498 }
499
500 res->tm_yday += st.wDay - 1;
501 res->tm_isdst = 0;
502
503 return 0;
504}
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
#define TICKS_1601_TO_1970
Definition: time.c:238
#define MAX_GMTIME64_TIME
Definition: time.c:71
static void write_invalid_msvcrt_tm(struct tm *tm)
Definition: time.c:85
static const int MonthLengths[2][12]
Definition: time.c:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
#define TRACE(s)
Definition: solgame.cpp:4
WORD wSecond
Definition: minwinbase.h:262
WORD wMinute
Definition: minwinbase.h:261
WORD wDayOfWeek
Definition: minwinbase.h:258
#define IsLeapYear(y)
Definition: variant.c:1048

Referenced by _gmtime32_s(), and _gmtime64().

◆ _localtime32()

struct tm *CDECL _localtime32 ( const __time32_t secs)

Definition at line 430 of file time.c.

431{
432 __time64_t secs64;
433
434 if(!secs)
435 return NULL;
436
437 secs64 = *secs;
438 return _localtime64( &secs64 );
439}

Referenced by _ctime32(), and _wctime32().

◆ _localtime32_s()

int CDECL _localtime32_s ( struct tm time,
const __time32_t secs 
)

Definition at line 444 of file time.c.

445{
446 __time64_t secs64;
447
448 if (!time || !secs || *secs < 0)
449 {
450 if (time)
452
453 *_errno() = EINVAL;
454 return EINVAL;
455 }
456
457 secs64 = *secs;
458 return _localtime64_s(time, &secs64);
459}

Referenced by _ctime32_s(), and _wctime32_s().

◆ _localtime64()

struct tm *CDECL _localtime64 ( const __time64_t secs)

Definition at line 415 of file time.c.

416{
418
419 if(!data->time_buffer)
420 data->time_buffer = malloc(sizeof(struct tm));
421
422 if(_localtime64_s(data->time_buffer, secs))
423 return NULL;
424 return data->time_buffer;
425}

Referenced by _ctime64(), _localtime32(), and _wctime64().

◆ _localtime64_s()

int CDECL _localtime64_s ( struct tm res,
const __time64_t secs 
)

Definition at line 367 of file time.c.

368{
369 int i;
370 FILETIME ft;
371 SYSTEMTIME st;
373
374 if (!res || !secs || *secs < 0 || *secs > _MAX__TIME64_T)
375 {
376 if (res)
378
379 *_errno() = EINVAL;
380 return EINVAL;
381 }
382
383 _tzset_init();
385
386 ft.dwHighDateTime = (UINT)(time >> 32);
387 ft.dwLowDateTime = (UINT)time;
388 FileTimeToSystemTime(&ft, &st);
389
390 res->tm_isdst = is_dst(&st) ? 1 : 0;
391 if(res->tm_isdst) {
393 ft.dwHighDateTime = (UINT)(time >> 32);
394 ft.dwLowDateTime = (UINT)time;
395 FileTimeToSystemTime(&ft, &st);
396 }
397
398 res->tm_sec = st.wSecond;
399 res->tm_min = st.wMinute;
400 res->tm_hour = st.wHour;
401 res->tm_mday = st.wDay;
402 res->tm_year = st.wYear - 1900;
403 res->tm_mon = st.wMonth - 1;
404 res->tm_wday = st.wDayOfWeek;
405 for (i = res->tm_yday = 0; i < st.wMonth - 1; i++)
406 res->tm_yday += MonthLengths[IsLeapYear(st.wYear)][i];
407 res->tm_yday += st.wDay - 1;
408
409 return 0;
410}
#define _MAX__TIME64_T
Definition: msvcrt.h:339
static BOOL is_dst(const SYSTEMTIME *st)
Definition: time.c:196

Referenced by _ctime64_s(), _localtime32_s(), _localtime64(), and _wctime64_s().

◆ _mkgmtime32()

__time32_t CDECL _mkgmtime32 ( struct tm time)

Definition at line 358 of file time.c.

359{
361 return ret == (__time32_t)ret ? ret : -1;
362}
__msvcrt_long __time32_t
Definition: corecrt.h:209
__time64_t CDECL _mkgmtime64(struct tm *time)
Definition: time.c:350

◆ _mkgmtime64()

__time64_t CDECL _mkgmtime64 ( struct tm time)

Definition at line 350 of file time.c.

351{
352 return mktime_helper(time, FALSE);
353}
#define FALSE
Definition: types.h:117
static __time64_t mktime_helper(struct tm *mstm, BOOL local)
Definition: time.c:240

Referenced by _mkgmtime(), and _mkgmtime32().

◆ _mktime32()

__time32_t CDECL _mktime32 ( struct tm mstm)

Definition at line 339 of file time.c.

340{
341 __time64_t ret = _mktime64( mstm );
342 return ret == (__time32_t)ret ? ret : -1;
343}
__time64_t CDECL _mktime64(struct tm *mstm)
Definition: time.c:331

◆ _mktime64()

__time64_t CDECL _mktime64 ( struct tm mstm)

Definition at line 331 of file time.c.

332{
333 return mktime_helper(mstm, TRUE);
334}
#define TRUE
Definition: types.h:120

Referenced by _mktime32().

◆ _strdate()

char *CDECL _strdate ( char date)

Definition at line 552 of file time.c.

553{
554 SYSTEMTIME st;
555
556 GetLocalTime(&st);
557 date[0] = '0' + st.wMonth / 10;
558 date[1] = '0' + st.wMonth % 10;
559 date[2] = '/';
560 date[3] = '0' + st.wDay / 10;
561 date[4] = '0' + st.wDay % 10;
562 date[5] = '/';
563 date[6] = '0' + st.wYear / 10 % 10;
564 date[7] = '0' + st.wYear % 10;
565 date[8] = 0;
566 return date;
567}
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:286
__u16 date
Definition: mkdosfs.c:8

◆ _strdate_s()

int CDECL _strdate_s ( char date,
size_t  size 
)

Definition at line 572 of file time.c.

573{
574 if(date && size)
575 date[0] = '\0';
576
577 if(!date) {
578 *_errno() = EINVAL;
579 return EINVAL;
580 }
581
582 if(size < 9) {
583 *_errno() = ERANGE;
584 return ERANGE;
585 }
586
587 _strdate(date);
588 return 0;
589}
GLsizeiptr size
Definition: glext.h:5919
_strdate
Definition: time.h:297

◆ _Strftime()

size_t CDECL _Strftime ( char str,
size_t  max,
const char format,
const struct tm mstm,
void time_data 
)

Definition at line 1528 of file time.c.

1530{
1531 return strftime_helper(str, max, format, mstm, time_data, NULL);
1532}
static size_t strftime_helper(char *str, size_t max, const char *format, const struct tm *mstm, __lc_time_data *time_data, _locale_t loc)
Definition: time.c:1466
const WCHAR * str
Definition: format.c:58
#define max(a, b)
Definition: svc.c:63

◆ _strtime()

char *CDECL _strtime ( char time)

Definition at line 625 of file time.c.

626{
627 SYSTEMTIME st;
628
629 GetLocalTime(&st);
630 time[0] = '0' + st.wHour / 10;
631 time[1] = '0' + st.wHour % 10;
632 time[2] = ':';
633 time[3] = '0' + st.wMinute / 10;
634 time[4] = '0' + st.wMinute % 10;
635 time[5] = ':';
636 time[6] = '0' + st.wSecond / 10;
637 time[7] = '0' + st.wSecond % 10;
638 time[8] = 0;
639 return time;
640}

◆ _strtime_s()

int CDECL _strtime_s ( char time,
size_t  size 
)

Definition at line 645 of file time.c.

646{
647 if(time && size)
648 time[0] = '\0';
649
650 if(!time) {
651 *_errno() = EINVAL;
652 return EINVAL;
653 }
654
655 if(size < 9) {
656 *_errno() = ERANGE;
657 return ERANGE;
658 }
659
660 _strtime(time);
661 return 0;
662}
_strtime
Definition: time.h:313

◆ _time32()

__time32_t CDECL _time32 ( __time32_t buf)

Definition at line 794 of file time.c.

795{
796 __time32_t curtime;
797 struct __timeb64 tb;
798
799 _ftime64(&tb);
800
801 curtime = tb.time;
802 return buf ? *buf = curtime : curtime;
803}
static const WCHAR tb[]
Definition: suminfo.c:285

◆ _time64()

__time64_t CDECL _time64 ( __time64_t buf)

Definition at line 780 of file time.c.

781{
782 __time64_t curtime;
783 struct __timeb64 tb;
784
785 _ftime64(&tb);
786
787 curtime = tb.time;
788 return buf ? *buf = curtime : curtime;
789}

◆ _tzset()

void CDECL _tzset ( void  )

Definition at line 127 of file time.c.

128{
129 char *tz = getenv("TZ");
130 BOOL error;
131
133 if(tz && tz[0]) {
134 BOOL neg_zone = FALSE;
135
136 memset(&tzi, 0, sizeof(tzi));
137
138 /* Parse timezone information: tzn[+|-]hh[:mm[:ss]][dzn] */
140 tz += 3;
141
142 if(*tz == '-') {
143 neg_zone = TRUE;
144 tz++;
145 }else if(*tz == '+') {
146 tz++;
147 }
148 MSVCRT___timezone = strtol(tz, &tz, 10)*3600;
149 if(*tz == ':') {
150 MSVCRT___timezone += strtol(tz+1, &tz, 10)*60;
151 if(*tz == ':')
152 MSVCRT___timezone += strtol(tz+1, &tz, 10);
153 }
154 if(neg_zone)
156
163
167 }else {
169 MSVCRT__dstbias = 0;
170 }
171
173 sizeof(tzname_std), NULL, &error) || error)
174 *MSVCRT__tzname[0] = 0;
176 sizeof(tzname_dst), NULL, &error) || error)
177 *MSVCRT__tzname[0] = 0;
178 }
180}
#define CP_ACP
Definition: compat.h:109
#define lstrcpynA
Definition: compat.h:751
#define WideCharToMultiByte
Definition: compat.h:111
char *CDECL getenv(const char *name)
Definition: environ.c:227
_ACRTIMP __msvcrt_long __cdecl strtol(const char *, char **, int)
Definition: string.c:1833
void CDECL _lock(int locknum)
Definition: lock.c:85
void CDECL _unlock(int locknum)
Definition: lock.c:114
#define _TIME_LOCK
Definition: mtdll.h:35
static TIME_ZONE_INFORMATION tzi
Definition: time.c:123
unsigned int BOOL
Definition: ntddk_ex.h:94
GLbyte GLbyte tz
Definition: glext.h:8756
#define error(str)
Definition: mkdosfs.c:1605
#define memset(x, y, z)
Definition: compat.h:39
SYSTEMTIME DaylightDate
Definition: winbase.h:936
WCHAR DaylightName[32]
Definition: winbase.h:935
WCHAR StandardName[32]
Definition: winbase.h:932
SYSTEMTIME StandardDate
Definition: winbase.h:933
#define TIME_ZONE_ID_INVALID
Definition: winbase.h:310

Referenced by _tzset_init(), strftime_impl(), and test__tzset().

◆ _tzset_init()

static void _tzset_init ( void  )
static

Definition at line 182 of file time.c.

183{
184 static BOOL init = FALSE;
185
186 if(!init) {
188 if(!init) {
189 _tzset();
190 init = TRUE;
191 }
193 }
194}
void CDECL _tzset(void)
Definition: time.c:127
static int init
Definition: wintirpc.c:33

Referenced by _ftime64(), _localtime64_s(), and mktime_helper().

◆ _wasctime()

wchar_t *CDECL _wasctime ( const struct tm mstm)

Definition at line 1677 of file time.c.

1678{
1680 char buffer[26];
1681
1682 if(!data->wasctime_buffer) {
1683 data->wasctime_buffer = malloc(26*sizeof(wchar_t));
1684 if(!data->wasctime_buffer) {
1685 *_errno() = ENOMEM;
1686 return NULL;
1687 }
1688 }
1689
1690 if(!asctime_buf(buffer, mstm))
1691 return NULL;
1692
1693 MultiByteToWideChar(CP_ACP, 0, buffer, -1, data->wasctime_buffer, 26);
1694 return data->wasctime_buffer;
1695}
#define MultiByteToWideChar
Definition: compat.h:110
#define ENOMEM
Definition: errno.h:35
static char * asctime_buf(char *buf, const struct tm *mstm)
Definition: time.c:1603
GLuint buffer
Definition: glext.h:5915

Referenced by _wctime32(), and _wctime64().

◆ _wasctime_s()

int CDECL _wasctime_s ( wchar_t time,
size_t  size,
const struct tm mstm 
)

Definition at line 1700 of file time.c.

1701{
1702 char buffer[26];
1703 int ret;
1704
1705 if (!MSVCRT_CHECK_PMT(time != NULL)) return EINVAL;
1706 if (size) time[0] = 0;
1707 if (!MSVCRT_CHECK_PMT(size >= 26)) return EINVAL;
1708 if (!MSVCRT_CHECK_PMT(mstm != NULL)) return EINVAL;
1709
1710 ret = asctime_s(buffer, sizeof(buffer), mstm);
1711 if(ret)
1712 return ret;
1714 return 0;
1715}

Referenced by _wctime32_s(), and _wctime64_s().

◆ _wcsftime_l()

size_t CDECL _wcsftime_l ( wchar_t str,
size_t  max,
const wchar_t format,
const struct tm mstm,
_locale_t  loc 
)

Definition at line 1576 of file time.c.

1578{
1579 return wcsftime_helper(str, max, format, mstm, NULL, loc);
1580}
static size_t wcsftime_helper(wchar_t *str, size_t max, const wchar_t *format, const struct tm *mstm, __lc_time_data *time_data, _locale_t loc)
Definition: time.c:1543

◆ _wctime32()

wchar_t *CDECL _wctime32 ( const __time32_t time)

Definition at line 1790 of file time.c.

1791{
1792 return _wasctime( _localtime32(time) );
1793}
wchar_t *CDECL _wasctime(const struct tm *mstm)
Definition: time.c:1677

◆ _wctime32_s()

int CDECL _wctime32_s ( wchar_t buf,
size_t  size,
const __time32_t time 
)

Definition at line 1821 of file time.c.

1823{
1824 struct tm tm;
1825 int ret;
1826
1827 if(!MSVCRT_CHECK_PMT(buf != NULL)) return EINVAL;
1828 if(!MSVCRT_CHECK_PMT(size != 0)) return EINVAL;
1829 buf[0] = 0;
1830 if(!MSVCRT_CHECK_PMT(time != NULL)) return EINVAL;
1831 if(!MSVCRT_CHECK_PMT(*time >= 0)) return EINVAL;
1832
1834 if(ret != 0)
1835 return ret;
1836
1837 return _wasctime_s(buf, size, &tm);
1838}
int CDECL _wasctime_s(wchar_t *time, size_t size, const struct tm *mstm)
Definition: time.c:1700

◆ _wctime64()

wchar_t *CDECL _wctime64 ( const __time64_t time)

Definition at line 1782 of file time.c.

1783{
1784 return _wasctime( _localtime64(time) );
1785}

◆ _wctime64_s()

int CDECL _wctime64_s ( wchar_t buf,
size_t  size,
const __time64_t time 
)

Definition at line 1798 of file time.c.

1800{
1801 struct tm tm;
1802 int ret;
1803
1804 if(!MSVCRT_CHECK_PMT(buf != NULL)) return EINVAL;
1805 if(!MSVCRT_CHECK_PMT(size != 0)) return EINVAL;
1806 buf[0] = 0;
1807 if(!MSVCRT_CHECK_PMT(time != NULL)) return EINVAL;
1808 if(!MSVCRT_CHECK_PMT(*time >= 0)) return EINVAL;
1809 if(!MSVCRT_CHECK_PMT(*time <= _MAX__TIME64_T)) return EINVAL;
1810
1812 if(ret != 0)
1813 return ret;
1814
1815 return _wasctime_s(buf, size, &tm);
1816}

◆ _wstrdate()

wchar_t *CDECL _wstrdate ( wchar_t date)

Definition at line 594 of file time.c.

595{
596 GetDateFormatW(LOCALE_NEUTRAL, 0, NULL, L"MM'/'dd'/'yy", date, 9);
597 return date;
598}
#define L(x)
Definition: resources.c:13
INT WINAPI GetDateFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpDateStr, INT cchOut)
Definition: lcformat.c:989
#define LOCALE_NEUTRAL

◆ _wstrdate_s()

int CDECL _wstrdate_s ( wchar_t date,
size_t  size 
)

Definition at line 603 of file time.c.

604{
605 if(date && size)
606 date[0] = '\0';
607
608 if(!date) {
609 *_errno() = EINVAL;
610 return EINVAL;
611 }
612
613 if(size < 9) {
614 *_errno() = ERANGE;
615 return ERANGE;
616 }
617
619 return 0;
620}
_wstrdate

◆ _wstrtime()

wchar_t *CDECL _wstrtime ( wchar_t time)

Definition at line 667 of file time.c.

668{
669 GetTimeFormatW(LOCALE_NEUTRAL, 0, NULL, L"HH':'mm':'ss", time, 9);
670 return time;
671}
INT WINAPI GetTimeFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchOut)
Definition: lcformat.c:1089

◆ _wstrtime_s()

int CDECL _wstrtime_s ( wchar_t time,
size_t  size 
)

Definition at line 676 of file time.c.

677{
678 if(time && size)
679 time[0] = '\0';
680
681 if(!time) {
682 *_errno() = EINVAL;
683 return EINVAL;
684 }
685
686 if(size < 9) {
687 *_errno() = ERANGE;
688 return ERANGE;
689 }
690
692 return 0;
693}
_wstrtime

◆ asctime()

char *CDECL asctime ( const struct tm mstm)

Definition at line 1636 of file time.c.

1637{
1639
1640 /* asctime returns date in format that always has exactly 26 characters */
1641 if (!data->asctime_buffer) {
1642 data->asctime_buffer = malloc(26);
1643 if (!data->asctime_buffer) {
1644 *_errno() = ENOMEM;
1645 return NULL;
1646 }
1647 }
1648
1649 return asctime_buf(data->asctime_buffer, mstm);
1650}

Referenced by _ctime32(), _ctime64(), ConvertTimeString(), create_msft_typelib(), DaytimeHandler(), kbd_c(), kbd_h(), Test_asctime(), and test_asctime().

◆ asctime_buf()

static char * asctime_buf ( char buf,
const struct tm mstm 
)
static

Definition at line 1603 of file time.c.

1604{
1605 static const char wday[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
1606 static const char month[12][4] = {"Jan", "Feb", "Mar", "Apr", "May",
1607 "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1608
1609 if (!mstm || mstm->tm_sec<0 || mstm->tm_sec>59
1610 || mstm->tm_min<0 || mstm->tm_min>59
1611 || mstm->tm_hour<0 || mstm->tm_hour>23
1612 || mstm->tm_mon<0 || mstm->tm_mon>11
1613 || mstm->tm_wday<0 || mstm->tm_wday>6
1614 || mstm->tm_year<0 || mstm->tm_mday<0
1615 || mstm->tm_mday>MonthLengths[IsLeapYear(1900+mstm->tm_year)][mstm->tm_mon]) {
1616 *_errno() = EINVAL;
1617 return NULL;
1618 }
1619
1620#if _MSVCR_VER>=140
1621 /* C89 (4.12.3.1) uses space-padding for day of month. */
1622 _snprintf(buf, 26, "%s %s %2d %02d:%02d:%02d %c%03d\n", wday[mstm->tm_wday],
1623 month[mstm->tm_mon], mstm->tm_mday, mstm->tm_hour, mstm->tm_min,
1624 mstm->tm_sec, '1'+(mstm->tm_year+900)/1000, (900+mstm->tm_year)%1000);
1625#else
1626 _snprintf(buf, 26, "%s %s %02d %02d:%02d:%02d %c%03d\n", wday[mstm->tm_wday],
1627 month[mstm->tm_mon], mstm->tm_mday, mstm->tm_hour, mstm->tm_min,
1628 mstm->tm_sec, '1'+(mstm->tm_year+900)/1000, (900+mstm->tm_year)%1000);
1629#endif
1630 return buf;
1631}
static const WCHAR month[12][4]
Definition: session.c:2150
int tm_mon
Definition: corecrt_wtime.h:16
int tm_year
Definition: corecrt_wtime.h:17
int tm_hour
Definition: corecrt_wtime.h:14
int tm_sec
Definition: corecrt_wtime.h:12
int tm_mday
Definition: corecrt_wtime.h:15
int tm_min
Definition: corecrt_wtime.h:13
int tm_wday
Definition: corecrt_wtime.h:18
#define _snprintf
Definition: xmlstorage.h:200

Referenced by _wasctime(), asctime(), and asctime_s().

◆ asctime_s()

int CDECL asctime_s ( char time,
size_t  size,
const struct tm mstm 
)

Definition at line 1655 of file time.c.

1656{
1657 if (!MSVCRT_CHECK_PMT(time != NULL)) return EINVAL;
1658 if (size) time[0] = 0;
1659 if (!MSVCRT_CHECK_PMT(size >= 26)) return EINVAL;
1660 if (!MSVCRT_CHECK_PMT(mstm != NULL)) return EINVAL;
1661 if (!MSVCRT_CHECK_PMT(mstm->tm_sec >= 0 && mstm->tm_sec < 60)) return EINVAL;
1662 if (!MSVCRT_CHECK_PMT(mstm->tm_min >= 0 && mstm->tm_min < 60)) return EINVAL;
1663 if (!MSVCRT_CHECK_PMT(mstm->tm_hour >= 0 && mstm->tm_hour < 24)) return EINVAL;
1664 if (!MSVCRT_CHECK_PMT(mstm->tm_mon >= 0 && mstm->tm_mon < 12)) return EINVAL;
1665 if (!MSVCRT_CHECK_PMT(mstm->tm_wday >= 0 && mstm->tm_wday < 7)) return EINVAL;
1666 if (!MSVCRT_CHECK_PMT(mstm->tm_year >= 0)) return EINVAL;
1667 if (!MSVCRT_CHECK_PMT(mstm->tm_mday >= 0)) return EINVAL;
1668 if (!MSVCRT_CHECK_PMT(mstm->tm_mday <= MonthLengths[IsLeapYear(1900+mstm->tm_year)][mstm->tm_mon])) return EINVAL;
1669
1670 asctime_buf(time, mstm);
1671 return 0;
1672}

Referenced by _ctime32_s(), _ctime64_s(), and _wasctime_s().

◆ clock()

clock_t CDECL clock ( void  )

Definition at line 698 of file time.c.

699{
700 LARGE_INTEGER systime;
701
702 NtQuerySystemTime(&systime);
703 return (systime.QuadPart - init_time) / (TICKSPERSEC / CLOCKS_PER_SEC);
704}
#define CLOCKS_PER_SEC
Definition: time.h:33
static LONGLONG init_time
Definition: time.c:47
NTSTATUS NTAPI NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
Definition: time.c:569
LONGLONG QuadPart
Definition: typedefs.h:114

◆ is_dst()

static BOOL is_dst ( const SYSTEMTIME st)
static

Definition at line 196 of file time.c.

197{
200
202 return FALSE;
203
205 tmp = tzi;
206 }else if(st->wYear >= 2007) {
207 memset(&tmp, 0, sizeof(tmp));
208 tmp.StandardDate.wMonth = 11;
209 tmp.StandardDate.wDay = 1;
210 tmp.StandardDate.wHour = 2;
211 tmp.DaylightDate.wMonth = 3;
212 tmp.DaylightDate.wDay = 2;
213 tmp.DaylightDate.wHour = 2;
214 }else {
215 memset(&tmp, 0, sizeof(tmp));
216 tmp.StandardDate.wMonth = 10;
217 tmp.StandardDate.wDay = 5;
218 tmp.StandardDate.wHour = 2;
219 tmp.DaylightDate.wMonth = 4;
220 tmp.DaylightDate.wDay = 1;
221 tmp.DaylightDate.wHour = 2;
222 }
223
224 tmp.Bias = 0;
225 tmp.StandardBias = 0;
227 if(!SystemTimeToTzSpecificLocalTime(&tmp, st, &out))
228 return FALSE;
229
230 return memcmp(st, &out, sizeof(SYSTEMTIME));
231}
BOOL WINAPI SystemTimeToTzSpecificLocalTime(CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation, CONST SYSTEMTIME *lpUniversalTime, LPSYSTEMTIME lpLocalTime)
Definition: timezone.c:377
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383

Referenced by _localtime64_s(), and mktime_helper().

◆ IsLeapYear()

static BOOL IsLeapYear ( int  Year)
inlinestatic

Definition at line 80 of file time.c.

81{
82 return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0);
83}

◆ mktime_helper()

static __time64_t mktime_helper ( struct tm mstm,
BOOL  local 
)
static

Definition at line 240 of file time.c.

241{
242 SYSTEMTIME st;
243 FILETIME ft;
244 __time64_t ret = 0;
245 int i;
246 BOOL use_dst = FALSE;
247
248 ret = mstm->tm_year + mstm->tm_mon/12;
249 mstm->tm_mon %= 12;
250 if(mstm->tm_mon < 0) {
251 mstm->tm_mon += 12;
252 ret--;
253 }
254
255 if(ret<70 || ret>1100) {
256 *_errno() = EINVAL;
257 return -1;
258 }
259
260 memset(&st, 0, sizeof(SYSTEMTIME));
261 st.wDay = 1;
262 st.wMonth = mstm->tm_mon+1;
263 st.wYear = ret+1900;
264
265 if(!SystemTimeToFileTime(&st, &ft)) {
266 *_errno() = EINVAL;
267 return -1;
268 }
269
272 ret += (__time64_t)mstm->tm_min*60*TICKSPERSEC;
273 ret += (__time64_t)mstm->tm_hour*60*60*TICKSPERSEC;
275
276 ft.dwLowDateTime = ret & 0xffffffff;
277 ft.dwHighDateTime = ret >> 32;
278 FileTimeToSystemTime(&ft, &st);
279
280 if(local) {
281 _tzset_init();
282 use_dst = is_dst(&st);
283 if((mstm->tm_isdst<=-1 && use_dst) || (mstm->tm_isdst>=1)) {
284 SYSTEMTIME tmp;
285
287
288 ft.dwLowDateTime = ret & 0xffffffff;
289 ft.dwHighDateTime = ret >> 32;
290 FileTimeToSystemTime(&ft, &tmp);
291
292 if(!is_dst(&tmp)) {
293 st = tmp;
294 use_dst = FALSE;
295 }else {
296 use_dst = TRUE;
297 }
298 }else if(mstm->tm_isdst==0 && use_dst) {
300 ft.dwLowDateTime = ret & 0xffffffff;
301 ft.dwHighDateTime = ret >> 32;
302 FileTimeToSystemTime(&ft, &st);
304 }
306 }
307
308 mstm->tm_sec = st.wSecond;
309 mstm->tm_min = st.wMinute;
310 mstm->tm_hour = st.wHour;
311 mstm->tm_mday = st.wDay;
312 mstm->tm_mon = st.wMonth-1;
313 mstm->tm_year = st.wYear-1900;
314 mstm->tm_wday = st.wDayOfWeek;
315 for(i=mstm->tm_yday=0; i<st.wMonth-1; i++)
316 mstm->tm_yday += MonthLengths[IsLeapYear(st.wYear)][i];
317 mstm->tm_yday += st.wDay-1;
318 mstm->tm_isdst = use_dst ? 1 : 0;
319
320 if(ret < TICKS_1601_TO_1970) {
321 *_errno() = EINVAL;
322 return -1;
323 }
325 return ret;
326}
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
Definition: time.c:158
#define SECSPERDAY
Definition: time.c:233
#define local
Definition: zutil.h:30
int tm_isdst
Definition: corecrt_wtime.h:20
int tm_yday
Definition: corecrt_wtime.h:19

Referenced by _mkgmtime64(), and _mktime64().

◆ msvcrt_init_clock()

void msvcrt_init_clock ( void  )

Definition at line 49 of file time.c.

50{
51 LARGE_INTEGER systime;
52
53 NtQuerySystemTime(&systime);
54 init_time = systime.QuadPart;
55}

Referenced by DllMain().

◆ strftime()

size_t CDECL strftime ( char str,
size_t  max,
const char format,
const struct tm mstm 
)

Definition at line 1537 of file time.c.

1539{
1540 return strftime_helper(str, max, format, mstm, NULL, NULL);
1541}

◆ strftime_format()

static BOOL strftime_format ( STRFTIME_CHAR str,
size_t pos,
size_t  max,
const struct tm mstm,
__lc_time_data time_data,
const STRFTIME_CHAR format 
)
inlinestatic

Definition at line 941 of file time.c.

943{
944 size_t count;
945 BOOL ret = TRUE;
946
947 while(*format && ret)
948 {
949 count = 1;
950 while(format[0] == format[count]) count++;
951
952 switch(*format) {
953 case '\'':
954 if(count % 2 == 0) break;
955
956 format += count;
957 count = 0;
958 while(format[count] && format[count] != '\'') count++;
959
961 if(!ret) return FALSE;
962 if(format[count] == '\'') count++;
963 break;
964 case 'd':
965 if(count > 2)
966 {
967 if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
968 {
969 *str = 0;
970 return FALSE;
971 }
972 }
973 switch(count) {
974 case 1:
975 case 2:
976 ret = strftime_int(str, pos, max, mstm->tm_mday, count==1 ? 0 : 2, 1, 31);
977 break;
978 case 3:
979 ret = strftime_str(str, pos, max, STRFTIME_TD(time_data, short_wday)[mstm->tm_wday]);
980 break;
981 default:
983 if(ret)
984 ret = strftime_str(str, pos, max, STRFTIME_TD(time_data, wday)[mstm->tm_wday]);
985 break;
986 }
987 break;
988 case 'M':
989 if(count > 2)
990 {
991 if(!MSVCRT_CHECK_PMT(mstm->tm_mon>=0 && mstm->tm_mon<=11))
992 {
993 *str = 0;
994 return FALSE;
995 }
996 }
997 switch(count) {
998 case 1:
999 case 2:
1000 ret = strftime_int(str, pos, max, mstm->tm_mon+1, count==1 ? 0 : 2, 1, 12);
1001 break;
1002 case 3:
1003 ret = strftime_str(str, pos, max, STRFTIME_TD(time_data, short_mon)[mstm->tm_mon]);
1004 break;
1005 default:
1007 if(ret)
1008 ret = strftime_str(str, pos, max, STRFTIME_TD(time_data, mon)[mstm->tm_mon]);
1009 break;
1010 }
1011 break;
1012 case 'y':
1013 if(count > 1)
1014 {
1015#if _MSVCR_VER>=140
1016 if(!MSVCRT_CHECK_PMT(mstm->tm_year >= -1900 && mstm->tm_year <= 8099))
1017#else
1018 if(!MSVCRT_CHECK_PMT(mstm->tm_year >= 0))
1019#endif
1020 {
1021 *str = 0;
1022 return FALSE;
1023 }
1024 }
1025
1026 switch(count) {
1027 case 1:
1028 ret = strftime_nstr(str, pos, max, format, 1);
1029 break;
1030 case 2:
1031 case 3:
1033 if(ret)
1034 ret = strftime_int(str, pos, max, (mstm->tm_year+1900)%100, 2, 0, 99);
1035 break;
1036 default:
1038 if(ret)
1039 ret = strftime_int(str, pos, max, mstm->tm_year+1900, 4, 0, 9999);
1040 break;
1041 }
1042 break;
1043 case 'h':
1044 if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
1045 {
1046 *str = 0;
1047 return FALSE;
1048 }
1049 if(count > 2)
1051 if(ret)
1052 ret = strftime_int(str, pos, max, (mstm->tm_hour + 11) % 12 + 1,
1053 count == 1 ? 0 : 2, 1, 12);
1054 break;
1055 case 'H':
1056 if(count > 2)
1058 if(ret)
1059 ret = strftime_int(str, pos, max, mstm->tm_hour, count == 1 ? 0 : 2, 0, 23);
1060 break;
1061 case 'm':
1062 if(count > 2)
1064 if(ret)
1065 ret = strftime_int(str, pos, max, mstm->tm_min, count == 1 ? 0 : 2, 0, 59);
1066 break;
1067 case 's':
1068 if(count > 2)
1070 if(ret)
1071 ret = strftime_int(str, pos, max, mstm->tm_sec, count == 1 ? 0 : 2, 0, MAX_SECONDS);
1072 break;
1073 case 'a':
1074 case 'A':
1075 case 't':
1076 if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
1077 {
1078 *str = 0;
1079 return FALSE;
1080 }
1082 mstm->tm_hour < 12 ? STRFTIME_TD(time_data, am) : STRFTIME_TD(time_data, pm),
1083 (*format == 't' && count == 1) ? 1 : SIZE_MAX);
1084 break;
1085 default:
1087 break;
1088 }
1089 format += count;
1090 }
1091
1092 return ret;
1093}
#define SIZE_MAX
Definition: limits.h:49
#define strftime_str(a, b, c, d)
Definition: time.c:896
static BOOL strftime_int(STRFTIME_CHAR *str, size_t *pos, size_t max, int src, int prec, int l, int h)
Definition: time.c:916
#define STRFTIME_TD(td, name)
Definition: time.c:890
static BOOL strftime_nstr(STRFTIME_CHAR *str, size_t *pos, size_t max, const STRFTIME_CHAR *src, size_t len)
Definition: time.c:897
static const int MAX_SECONDS
Definition: time.c:66
GLuint GLuint GLsizei count
Definition: gl.h:1545
static LPMONITOREX pm
Definition: localmon.c:45

Referenced by strftime_impl().

◆ strftime_helper()

static size_t strftime_helper ( char str,
size_t  max,
const char format,
const struct tm mstm,
__lc_time_data time_data,
_locale_t  loc 
)
static

Definition at line 1466 of file time.c.

1468{
1469#if _MSVCR_VER <= 90
1470 TRACE("(%p %Iu %s %p %p %p)\n", str, max, format, mstm, time_data, loc);
1471 return strftime_impl(str, max, format, mstm, time_data, loc);
1472#else
1473 wchar_t *s, *fmt;
1474 size_t len;
1475 int cp;
1476
1477 TRACE("(%p %Iu %s %p %p %p)\n", str, max, format, mstm, time_data, loc);
1478
1479 if (!MSVCRT_CHECK_PMT(str != NULL)) return 0;
1480 if (!MSVCRT_CHECK_PMT(max != 0)) return 0;
1481 *str = 0;
1482 if (!MSVCRT_CHECK_PMT(format != NULL)) return 0;
1483
1484 cp = (loc ? loc->locinfo : get_locinfo())->lc_id[LC_TIME].wCodePage;
1485
1486 len = MultiByteToWideChar( cp, 0, format, -1, NULL, 0 );
1487 if (!len)
1488 {
1489 *_errno() = EILSEQ;
1490 return 0;
1491 }
1492 fmt = malloc( len*sizeof(wchar_t) );
1493 if (!fmt) return 0;
1494 MultiByteToWideChar( cp, 0, format, -1, fmt, len );
1495
1496 if ((s = malloc( max*sizeof(wchar_t) )))
1497 {
1498 len = strftime_impl( s, max, fmt, mstm, time_data, loc );
1499 if (len)
1500 {
1501 len = WideCharToMultiByte( cp, 0, s, -1, str, max, NULL, NULL );
1502 if (len) len--;
1503 else *_errno() = EILSEQ;
1504 }
1505 free( s );
1506 }
1507 else len = 0;
1508
1509 free( fmt );
1510 return len;
1511#endif
1512}
#define free
Definition: debug_ros.c:5
#define EILSEQ
Definition: errno.h:62
#define LC_TIME
Definition: locale.h:30
static size_t strftime_impl(STRFTIME_CHAR *str, size_t max, const STRFTIME_CHAR *format, const struct tm *mstm, __lc_time_data *time_data, _locale_t loc)
Definition: time.c:1116
GLdouble s
Definition: gl.h:2039
POINT cp
Definition: magnifier.c:59
Definition: dsound.c:943
pthreadlocinfo locinfo
Definition: corecrt.h:260
#define get_locinfo()
Definition: winesup.h:25

Referenced by _Strftime(), and strftime().

◆ strftime_impl()

static size_t strftime_impl ( STRFTIME_CHAR str,
size_t  max,
const STRFTIME_CHAR format,
const struct tm mstm,
__lc_time_data time_data,
_locale_t  loc 
)
static

Definition at line 1116 of file time.c.

1119{
1120 size_t ret, tmp;
1121 BOOL alternate;
1122 int year = mstm ? mstm->tm_year + 1900 : -1;
1123
1124 if(!str || !format) {
1125 if(str && max)
1126 *str = 0;
1127 *_errno() = EINVAL;
1128 return 0;
1129 }
1130
1131 if(!time_data)
1132 time_data = loc ? loc->locinfo->lc_time_curr : get_locinfo()->lc_time_curr;
1133
1134 for(ret=0; *format && ret<max; format++) {
1135 if(*format != '%') {
1136 if(_isleadbyte_l((unsigned char)*format, loc)) {
1137 str[ret++] = *(format++);
1138 if(ret == max) continue;
1139 if(!MSVCRT_CHECK_PMT(str[ret]))
1140 goto einval_error;
1141 }
1142 str[ret++] = *format;
1143 continue;
1144 }
1145
1146 format++;
1147 if(*format == '#') {
1148 alternate = TRUE;
1149 format++;
1150 }else {
1151 alternate = FALSE;
1152 }
1153
1154 if(!MSVCRT_CHECK_PMT(mstm))
1155 goto einval_error;
1156
1157 switch(*format) {
1158 case 'c':
1159#if _MSVCR_VER>=140
1160 if(time_data == &cloc_time_data && !alternate)
1161 {
1162 tmp = strftime_impl(str+ret, max-ret, L"%a %b %e %T %Y", mstm, time_data, loc);
1163 if(!tmp)
1164 return 0;
1165 ret += tmp;
1166 break;
1167 }
1168#endif
1169 if(!strftime_format(str, &ret, max, mstm, time_data,
1170 alternate ? STRFTIME_TD(time_data, date) : STRFTIME_TD(time_data, short_date)))
1171 return 0;
1172 if(ret < max)
1173 str[ret++] = ' ';
1174 if(!strftime_format(str, &ret, max, mstm, time_data, STRFTIME_TD(time_data, time)))
1175 return 0;
1176 break;
1177 case 'x':
1178 if(!strftime_format(str, &ret, max, mstm, time_data,
1179 alternate ? STRFTIME_TD(time_data, date) : STRFTIME_TD(time_data, short_date)))
1180 return 0;
1181 break;
1182 case 'X':
1183 if(!strftime_format(str, &ret, max, mstm, time_data, STRFTIME_TD(time_data, time)))
1184 return 0;
1185 break;
1186 case 'a':
1187 if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
1188 goto einval_error;
1189 if(!strftime_str(str, &ret, max, STRFTIME_TD(time_data, short_wday)[mstm->tm_wday]))
1190 return 0;
1191 break;
1192 case 'A':
1193 if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
1194 goto einval_error;
1195 if(!strftime_str(str, &ret, max, STRFTIME_TD(time_data, wday)[mstm->tm_wday]))
1196 return 0;
1197 break;
1198 case 'b':
1199#if _MSVCR_VER>=140
1200 case 'h':
1201#endif
1202 if(!MSVCRT_CHECK_PMT(mstm->tm_mon>=0 && mstm->tm_mon<=11))
1203 goto einval_error;
1204 if(!strftime_str(str, &ret, max, STRFTIME_TD(time_data, short_mon)[mstm->tm_mon]))
1205 return 0;
1206 break;
1207 case 'B':
1208 if(!MSVCRT_CHECK_PMT(mstm->tm_mon>=0 && mstm->tm_mon<=11))
1209 goto einval_error;
1210 if(!strftime_str(str, &ret, max, STRFTIME_TD(time_data, mon)[mstm->tm_mon]))
1211 return 0;
1212 break;
1213#if _MSVCR_VER>=140
1214 case 'C':
1215 if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
1216 goto einval_error;
1217 if(!strftime_int(str, &ret, max, year/100, alternate ? 0 : 2, 0, 99))
1218 return 0;
1219 break;
1220#endif
1221 case 'd':
1222 if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 1, 31))
1223 return 0;
1224 break;
1225#if _MSVCR_VER>=140
1226 case 'D':
1227 if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
1228 goto einval_error;
1229 if(!strftime_int(str, &ret, max, mstm->tm_mon+1, alternate ? 0 : 2, 1, 12))
1230 return 0;
1231 if(ret < max)
1232 str[ret++] = '/';
1233 if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 1, 31))
1234 return 0;
1235 if(ret < max)
1236 str[ret++] = '/';
1237 if(!strftime_int(str, &ret, max, year%100, alternate ? 0 : 2, 0, 99))
1238 return 0;
1239 break;
1240 case 'e':
1241 if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 1, 31))
1242 return 0;
1243 if(!alternate && str[ret-2] == '0')
1244 str[ret-2] = ' ';
1245 break;
1246 case 'F':
1247 if(!strftime_int(str, &ret, max, year, alternate ? 0 : 4, 0, 9999))
1248 return 0;
1249 if(ret < max)
1250 str[ret++] = '-';
1251 if(!strftime_int(str, &ret, max, mstm->tm_mon+1, alternate ? 0 : 2, 1, 12))
1252 return 0;
1253 if(ret < max)
1254 str[ret++] = '-';
1255 if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 1, 31))
1256 return 0;
1257 break;
1258 case 'g':
1259 case 'G':
1260 if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
1261 goto einval_error;
1262 /* fall through */
1263 case 'V':
1264 {
1265 int iso_year = year;
1266 int iso_days = mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4;
1267 if (iso_days < 0)
1268 iso_days += 365 + IsLeapYear(--iso_year);
1269 else if(iso_days >= 365 + IsLeapYear(iso_year))
1270 iso_days -= 365 + IsLeapYear(iso_year++);
1271
1272 if(*format == 'G') {
1273 if(!strftime_int(str, &ret, max, iso_year, 4, 0, 9999))
1274 return 0;
1275 } else if(*format == 'g') {
1276 if(!strftime_int(str, &ret, max, iso_year%100, 2, 0, 99))
1277 return 0;
1278 } else {
1279 if(!strftime_int(str, &ret, max, iso_days/7 + 1, alternate ? 0 : 2, 0, 53))
1280 return 0;
1281 }
1282 break;
1283 }
1284#endif
1285 case 'H':
1286 if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23))
1287 return 0;
1288 break;
1289 case 'I':
1290 if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
1291 goto einval_error;
1292 if(!strftime_int(str, &ret, max, (mstm->tm_hour + 11) % 12 + 1,
1293 alternate ? 0 : 2, 1, 12))
1294 return 0;
1295 break;
1296 case 'j':
1297 if(!strftime_int(str, &ret, max, mstm->tm_yday+1, alternate ? 0 : 3, 1, 366))
1298 return 0;
1299 break;
1300 case 'm':
1301 if(!strftime_int(str, &ret, max, mstm->tm_mon+1, alternate ? 0 : 2, 1, 12))
1302 return 0;
1303 break;
1304 case 'M':
1305 if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59))
1306 return 0;
1307 break;
1308#if _MSVCR_VER>=140
1309 case 'n':
1310 str[ret++] = '\n';
1311 break;
1312#endif
1313 case 'p':
1314 if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
1315 goto einval_error;
1316 if(!strftime_str(str, &ret, max, mstm->tm_hour<12 ?
1317 STRFTIME_TD(time_data, am) : STRFTIME_TD(time_data, pm)))
1318 return 0;
1319 break;
1320#if _MSVCR_VER>=140
1321 case 'r':
1322 if(time_data == &cloc_time_data)
1323 {
1324 if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
1325 goto einval_error;
1326 if(!strftime_int(str, &ret, max, (mstm->tm_hour + 11) % 12 + 1,
1327 alternate ? 0 : 2, 1, 12))
1328 return 0;
1329 if(ret < max)
1330 str[ret++] = ':';
1331 if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59))
1332 return 0;
1333 if(ret < max)
1334 str[ret++] = ':';
1335 if(!strftime_int(str, &ret, max, mstm->tm_sec, alternate ? 0 : 2, 0, MAX_SECONDS))
1336 return 0;
1337 if(ret < max)
1338 str[ret++] = ' ';
1339 if(!strftime_str(str, &ret, max, mstm->tm_hour<12 ?
1340 STRFTIME_TD(time_data, am) : STRFTIME_TD(time_data, pm)))
1341 return 0;
1342 }
1343 else
1344 {
1345 if(!strftime_format(str, &ret, max, mstm, time_data, STRFTIME_TD(time_data, time)))
1346 return 0;
1347 }
1348 break;
1349 case 'R':
1350 if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23))
1351 return 0;
1352 if(ret < max)
1353 str[ret++] = ':';
1354 if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59))
1355 return 0;
1356 break;
1357#endif
1358 case 'S':
1359 if(!strftime_int(str, &ret, max, mstm->tm_sec, alternate ? 0 : 2, 0, MAX_SECONDS))
1360 return 0;
1361 break;
1362#if _MSVCR_VER>=140
1363 case 't':
1364 str[ret++] = '\t';
1365 break;
1366 case 'T':
1367 if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23))
1368 return 0;
1369 if(ret < max)
1370 str[ret++] = ':';
1371 if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59))
1372 return 0;
1373 if(ret < max)
1374 str[ret++] = ':';
1375 if(!strftime_int(str, &ret, max, mstm->tm_sec, alternate ? 0 : 2, 0, MAX_SECONDS))
1376 return 0;
1377 break;
1378 case 'u':
1379 if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
1380 goto einval_error;
1381 tmp = mstm->tm_wday ? mstm->tm_wday : 7;
1382 if(!strftime_int(str, &ret, max, tmp, 0, 1, 7))
1383 return 0;
1384 break;
1385#endif
1386 case 'w':
1387 if(!strftime_int(str, &ret, max, mstm->tm_wday, 0, 0, 6))
1388 return 0;
1389 break;
1390 case 'y':
1391#if _MSVCR_VER>=140
1392 if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
1393#else
1394 if(!MSVCRT_CHECK_PMT(year>=1900))
1395#endif
1396 goto einval_error;
1397 if(!strftime_int(str, &ret, max, year%100, alternate ? 0 : 2, 0, 99))
1398 return 0;
1399 break;
1400 case 'Y':
1401 if(!strftime_int(str, &ret, max, year, alternate ? 0 : 4, 0, 9999))
1402 return 0;
1403 break;
1404 case 'z':
1405#if _MSVCR_VER>=140
1406 _tzset();
1407 if(!strftime_tzdiff(str, &ret, max, mstm->tm_isdst))
1408 return 0;
1409 break;
1410#endif
1411 case 'Z':
1412 _tzset();
1413#if _MSVCR_VER <= 90
1414 if(_get_tzname(&tmp, str+ret, max-ret, mstm->tm_isdst ? 1 : 0))
1415 return 0;
1416#else
1417 if(_mbstowcs_s_l(&tmp, str+ret, max-ret,
1418 mstm->tm_isdst ? tzname_dst : tzname_std,
1419 _TRUNCATE, loc) == STRUNCATE)
1420 ret = max;
1421#endif
1422 ret += tmp-1;
1423 break;
1424 case 'U':
1425 case 'W':
1426 if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
1427 goto einval_error;
1428 if(!MSVCRT_CHECK_PMT(mstm->tm_yday>=0 && mstm->tm_yday<=365))
1429 goto einval_error;
1430 if(*format == 'U')
1431 tmp = mstm->tm_wday;
1432 else if(!mstm->tm_wday)
1433 tmp = 6;
1434 else
1435 tmp = mstm->tm_wday-1;
1436
1437 tmp = mstm->tm_yday/7 + (tmp<=mstm->tm_yday%7);
1438 if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 2, 0, 53))
1439 return 0;
1440 break;
1441 case '%':
1442 str[ret++] = '%';
1443 break;
1444 default:
1445 WARN("unknown format %c\n", *format);
1446 MSVCRT_INVALID_PMT("unknown format", EINVAL);
1447 goto einval_error;
1448 }
1449 }
1450
1451 if(ret == max) {
1452 if(max)
1453 *str = 0;
1454 *_errno() = ERANGE;
1455 return 0;
1456 }
1457
1458 str[ret] = 0;
1459 return ret;
1460
1461einval_error:
1462 *str = 0;
1463 return 0;
1464}
#define WARN(fmt,...)
Definition: precomp.h:61
#define _isleadbyte_l(_C, _L)
#define STRUNCATE
Definition: errno.h:64
#define _TRUNCATE
Definition: stdlib.h:45
__lc_time_data cloc_time_data
Definition: locale.c:60
#define MSVCRT_INVALID_PMT(x, err)
Definition: msvcrt.h:376
int CDECL _get_tzname(size_t *ret, char *buf, size_t bufsize, int index)
Definition: time.c:844
static BOOL strftime_format(STRFTIME_CHAR *str, size_t *pos, size_t max, const struct tm *mstm, __lc_time_data *time_data, const STRFTIME_CHAR *format)
Definition: time.c:941
_mbstowcs_s_l
Definition: stdlib.h:951
struct __lc_time_data * lc_time_curr
Definition: corecrt.h:309

Referenced by strftime_helper(), strftime_impl(), and wcsftime_helper().

◆ strftime_int()

static BOOL strftime_int ( STRFTIME_CHAR str,
size_t pos,
size_t  max,
int  src,
int  prec,
int  l,
int  h 
)
inlinestatic

Definition at line 916 of file time.c.

918{
919 size_t len;
920
921 if(!MSVCRT_CHECK_PMT(src>=l && src<=h)) {
922 *str = 0;
923 return FALSE;
924 }
925
926#if _MSVCR_VER <= 90
927 len = _snprintf(str+*pos, max-*pos, "%0*d", prec, src);
928#else
929 len = _snwprintf(str+*pos, max-*pos, L"%0*d", prec, src);
930#endif
931 if(len == -1) {
932 *str = 0;
933 *_errno() = ERANGE;
934 return FALSE;
935 }
936
937 *pos += len;
938 return TRUE;
939}
r l[0]
Definition: byte_order.h:168
_ACRTIMP int __cdecl _snwprintf(wchar_t *, size_t, const wchar_t *,...)
Definition: wcs.c:1493
GLenum src
Definition: glext.h:6340
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723

Referenced by strftime_format(), and strftime_impl().

◆ strftime_nstr()

static BOOL strftime_nstr ( STRFTIME_CHAR str,
size_t pos,
size_t  max,
const STRFTIME_CHAR src,
size_t  len 
)
inlinestatic

Definition at line 897 of file time.c.

899{
900 while(*src && len)
901 {
902 if(*pos >= max) {
903 *str = 0;
904 *_errno() = ERANGE;
905 return FALSE;
906 }
907
908 str[*pos] = *src;
909 src++;
910 *pos += 1;
911 len--;
912 }
913 return TRUE;
914}

Referenced by strftime_format().

◆ wcsftime()

size_t CDECL wcsftime ( wchar_t str,
size_t  max,
const wchar_t format,
const struct tm mstm 
)

Definition at line 1585 of file time.c.

1587{
1588 return wcsftime_helper(str, max, format, mstm, NULL, NULL);
1589}

◆ wcsftime_helper()

static size_t wcsftime_helper ( wchar_t str,
size_t  max,
const wchar_t format,
const struct tm mstm,
__lc_time_data time_data,
_locale_t  loc 
)
static

Definition at line 1543 of file time.c.

1546{
1547#if _MSVCR_VER <= 90
1548 char *s, *fmt;
1549 size_t len;
1550
1551 TRACE("%p %Iu %s %p %p %p\n", str, max, debugstr_w(format), mstm, time_data, loc);
1552
1553 len = _wcstombs_l( NULL, format, 0, loc ) + 1;
1554 if (!(fmt = malloc( len ))) return 0;
1555 _wcstombs_l(fmt, format, len, loc);
1556
1557 if ((s = malloc( max*4 )))
1558 {
1559 if (!strftime_impl( s, max*4, fmt, mstm, time_data, loc )) s[0] = 0;
1560 len = _mbstowcs_l( str, s, max, loc );
1561 free( s );
1562 }
1563 else len = 0;
1564
1565 free( fmt );
1566 return len;
1567#else
1568 TRACE("%p %Iu %s %p %p %p\n", str, max, debugstr_w(format), mstm, time_data, loc);
1569 return strftime_impl(str, max, format, mstm, time_data, loc);
1570#endif
1571}
#define debugstr_w
Definition: kernel32.h:32
_wcstombs_l
Definition: stdlib.h:1039
_mbstowcs_l
Definition: stdlib.h:951

Referenced by _wcsftime_l(), and wcsftime().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msvcrt  )

◆ write_invalid_msvcrt_tm()

static void write_invalid_msvcrt_tm ( struct tm tm)
inlinestatic

Definition at line 85 of file time.c.

86{
87 tm->tm_sec = -1;
88 tm->tm_min = -1;
89 tm->tm_hour = -1;
90 tm->tm_mday = -1;
91 tm->tm_mon = -1;
92 tm->tm_year = -1;
93 tm->tm_wday = -1;
94 tm->tm_yday = -1;
95 tm->tm_isdst = -1;
96}

Referenced by _gmtime64_s(), _localtime32_s(), and _localtime64_s().

Variable Documentation

◆ init_time

LONGLONG init_time
static

Definition at line 47 of file time.c.

Referenced by clock(), and msvcrt_init_clock().

◆ MAX_SECONDS

const int MAX_SECONDS = 59
static

Definition at line 66 of file time.c.

Referenced by strftime_format(), and strftime_impl().

◆ MonthLengths

const int MonthLengths[2][12]
static
Initial value:
=
{
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
}

Definition at line 57 of file time.c.

Referenced by _gmtime64_s(), _localtime64_s(), asctime_buf(), asctime_s(), mktime_helper(), RtlCutoverTimeToSystemTime(), RtlTimeFieldsToTime(), RtlTimeToTimeFields(), and test_pRtlTimeToTimeFields().

◆ MSVCRT___daylight

int MSVCRT___daylight = 1

Definition at line 101 of file time.c.

Referenced by __p__daylight(), _tzset(), and is_dst().

◆ MSVCRT___timezone

__msvcrt_long MSVCRT___timezone = 28800

Definition at line 106 of file time.c.

Referenced by __p__timezone(), _ftime64(), _localtime64_s(), _tzset(), and mktime_helper().

◆ MSVCRT__dstbias

__msvcrt_long MSVCRT__dstbias = -3600

Definition at line 111 of file time.c.

Referenced by __p__dstbias(), _localtime64_s(), _tzset(), is_dst(), and mktime_helper().

◆ MSVCRT__tzname

char* MSVCRT__tzname[2] = { tzname_std, tzname_dst }

Definition at line 121 of file time.c.

Referenced by __p__tzname(), and _tzset().

◆ tzi

TIME_ZONE_INFORMATION tzi = {0}
static

Definition at line 123 of file time.c.

Referenced by _tzset(), create_date(), date_parse(), get_localdatetime(), is_dst(), and mktime_worker().

◆ tzname_dst

char tzname_dst[64] = "PDT"
static

Definition at line 120 of file time.c.

Referenced by _get_tzname(), _tzset(), and strftime_impl().

◆ tzname_std

char tzname_std[64] = "PST"
static

Definition at line 119 of file time.c.

Referenced by _get_tzname(), _tzset(), and strftime_impl().