1 // 2 // time.h 3 // 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // 6 // The C Standard Library <time.h> header. 7 // 8 #pragma once 9 #ifndef _INC_TIME // include guard for 3rd party interop 10 #define _INC_TIME 11 12 #include <corecrt.h> 13 #include <corecrt_wtime.h> 14 15 #pragma warning(push) 16 #pragma warning(disable: _UCRT_DISABLED_WARNINGS) 17 _UCRT_DISABLE_CLANG_WARNINGS 18 19 _CRT_BEGIN_C_HEADER 20 21 #ifndef _CRT_USE_CONFORMING_ANNEX_K_TIME 22 #define _CRT_USE_CONFORMING_ANNEX_K_TIME 0 23 #endif 24 25 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 26 // 27 // Types 28 // 29 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 30 typedef long clock_t; 31 32 struct _timespec32 33 { 34 __time32_t tv_sec; 35 long tv_nsec; 36 }; 37 38 struct _timespec64 39 { 40 __time64_t tv_sec; 41 long tv_nsec; 42 }; 43 44 #ifndef _CRT_NO_TIME_T 45 struct timespec 46 { 47 time_t tv_sec; // Seconds - >= 0 48 long tv_nsec; // Nanoseconds - [0, 999999999] 49 }; 50 #endif 51 52 53 54 // The number of clock ticks per second 55 #define CLOCKS_PER_SEC ((clock_t)1000) 56 57 #define TIME_UTC 1 58 59 60 61 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 62 // 63 // Time Zone and Daylight Savings Time Data and Accessors 64 // 65 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 66 // Nonzero if Daylight Savings Time is used 67 _Check_return_ _CRT_INSECURE_DEPRECATE_GLOBALS(_get_daylight) 68 _ACRTIMP int* __cdecl __daylight(void); 69 70 #define _daylight (*__daylight()) 71 72 // Offset for Daylight Savings Time 73 _Check_return_ _CRT_INSECURE_DEPRECATE_GLOBALS(_get_dstbias) 74 _ACRTIMP long* __cdecl __dstbias(void); 75 76 #define _dstbias (*__dstbias()) 77 78 // Difference in seconds between GMT and local time 79 _Check_return_ _CRT_INSECURE_DEPRECATE_GLOBALS(_get_timezone) 80 _ACRTIMP long* __cdecl __timezone(void); 81 82 #define _timezone (*__timezone()) 83 84 // Standard and Daylight Savings Time time zone names 85 _Check_return_ _Deref_ret_z_ _CRT_INSECURE_DEPRECATE_GLOBALS(_get_tzname) 86 _ACRTIMP char** __cdecl __tzname(void); 87 88 #define _tzname (__tzname()) 89 90 _Success_(_Daylight != 0) 91 _ACRTIMP errno_t __cdecl _get_daylight( 92 _Out_ int* _Daylight 93 ); 94 95 _Success_(_DaylightSavingsBias != 0) 96 _ACRTIMP errno_t __cdecl _get_dstbias( 97 _Out_ long* _DaylightSavingsBias 98 ); 99 100 _Success_(_TimeZone != 0) 101 _ACRTIMP errno_t __cdecl _get_timezone( 102 _Out_ long* _TimeZone 103 ); 104 105 _Success_(return == 0) 106 _ACRTIMP errno_t __cdecl _get_tzname( 107 _Out_ size_t* _ReturnValue, 108 _Out_writes_z_(_SizeInBytes) char* _Buffer, 109 _In_ size_t _SizeInBytes, 110 _In_ int _Index 111 ); 112 113 114 115 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 116 // 117 // AppCRT Time Functions 118 // 119 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 120 _Success_(return != 0) 121 _Ret_writes_z_(26) 122 _Check_return_ _CRT_INSECURE_DEPRECATE(asctime_s) 123 _ACRTIMP char* __cdecl asctime( 124 _In_ struct tm const* _Tm 125 ); 126 127 #if __STDC_WANT_SECURE_LIB__ 128 _Success_(return == 0) 129 _Check_return_wat_ 130 _ACRTIMP errno_t __cdecl asctime_s( 131 _Out_writes_(_SizeInBytes) _Post_readable_size_(26) char* _Buffer, 132 _In_range_(>=,26) size_t _SizeInBytes, 133 _In_ struct tm const* _Tm 134 ); 135 #endif 136 137 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1( 138 errno_t, asctime_s, 139 _Post_readable_size_(26) char, _Buffer, 140 _In_ struct tm const*, _Time 141 ) 142 143 _Check_return_ 144 _ACRTIMP clock_t __cdecl clock(void); 145 146 _Ret_z_ 147 _Success_(return != 0) 148 _Check_return_ _CRT_INSECURE_DEPRECATE(_ctime32_s) 149 _ACRTIMP char* __cdecl _ctime32( 150 _In_ __time32_t const* _Time 151 ); 152 153 _Check_return_wat_ 154 _ACRTIMP errno_t __cdecl _ctime32_s( 155 _Out_writes_(_SizeInBytes) _Post_readable_size_(26) char* _Buffer, 156 _In_range_(>=,26) size_t _SizeInBytes, 157 _In_ __time32_t const* _Time 158 ); 159 160 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1( 161 errno_t, _ctime32_s, 162 _Post_readable_size_(26) char, _Buffer, 163 _In_ __time32_t const*, _Time 164 ) 165 166 _Ret_z_ 167 _Success_(return != 0) 168 _Check_return_ _CRT_INSECURE_DEPRECATE(_ctime64_s) 169 _ACRTIMP char* __cdecl _ctime64( 170 _In_ __time64_t const* _Time 171 ); 172 173 _Check_return_wat_ 174 _ACRTIMP errno_t __cdecl _ctime64_s( 175 _Out_writes_z_(_SizeInBytes) _Post_readable_size_(26) char* _Buffer, 176 _In_range_(>=,26) size_t _SizeInBytes, 177 _In_ __time64_t const* _Time 178 ); 179 180 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1( 181 errno_t, _ctime64_s, 182 _Post_readable_size_(26) char, _Buffer, 183 _In_ __time64_t const*, _Time 184 ) 185 186 _Check_return_ 187 _ACRTIMP double __cdecl _difftime32( 188 _In_ __time32_t _Time1, 189 _In_ __time32_t _Time2 190 ); 191 192 _Check_return_ 193 _ACRTIMP double __cdecl _difftime64( 194 _In_ __time64_t _Time1, 195 _In_ __time64_t _Time2 196 ); 197 198 _Success_(return != 0) 199 _Check_return_ _CRT_INSECURE_DEPRECATE(_gmtime32_s) 200 _ACRTIMP struct tm* __cdecl _gmtime32( 201 _In_ __time32_t const* _Time 202 ); 203 204 _Check_return_wat_ 205 _ACRTIMP errno_t __cdecl _gmtime32_s( 206 _Out_ struct tm* _Tm, 207 _In_ __time32_t const* _Time 208 ); 209 210 _Success_(return != 0) 211 _Check_return_ _CRT_INSECURE_DEPRECATE(_gmtime64_s) 212 _ACRTIMP struct tm* __cdecl _gmtime64( 213 _In_ __time64_t const* _Time 214 ); 215 216 _Check_return_wat_ 217 _ACRTIMP errno_t __cdecl _gmtime64_s( 218 _Out_ struct tm* _Tm, 219 _In_ __time64_t const* _Time 220 ); 221 222 _Success_(return != 0) 223 _Check_return_ _CRT_INSECURE_DEPRECATE(_localtime32_s) 224 _ACRTIMP struct tm* __cdecl _localtime32( 225 _In_ __time32_t const* _Time 226 ); 227 228 _Check_return_wat_ 229 _ACRTIMP errno_t __cdecl _localtime32_s( 230 _Out_ struct tm* _Tm, 231 _In_ __time32_t const* _Time 232 ); 233 234 _Success_(return != 0) 235 _Check_return_ _CRT_INSECURE_DEPRECATE(_localtime64_s) 236 _ACRTIMP struct tm* __cdecl _localtime64( 237 _In_ __time64_t const* _Time 238 ); 239 240 _Check_return_wat_ 241 _ACRTIMP errno_t __cdecl _localtime64_s( 242 _Out_ struct tm* _Tm, 243 _In_ __time64_t const* _Time 244 ); 245 246 _Check_return_ 247 _ACRTIMP __time32_t __cdecl _mkgmtime32( 248 _Inout_ struct tm* _Tm 249 ); 250 251 _Check_return_ 252 _ACRTIMP __time64_t __cdecl _mkgmtime64( 253 _Inout_ struct tm* _Tm 254 ); 255 256 _Check_return_opt_ 257 _ACRTIMP __time32_t __cdecl _mktime32( 258 _Inout_ struct tm* _Tm 259 ); 260 261 _Check_return_opt_ 262 _ACRTIMP __time64_t __cdecl _mktime64( 263 _Inout_ struct tm* _Tm 264 ); 265 266 _Success_(return > 0) 267 _Check_return_wat_ 268 _ACRTIMP size_t __cdecl strftime( 269 _Out_writes_z_(_SizeInBytes) char* _Buffer, 270 _In_ size_t _SizeInBytes, 271 _In_z_ _Printf_format_string_ char const* _Format, 272 _In_ struct tm const* _Tm 273 ); 274 275 _Success_(return > 0) 276 _Check_return_wat_ 277 _ACRTIMP size_t __cdecl _strftime_l( 278 _Out_writes_z_(_MaxSize) char* _Buffer, 279 _In_ size_t _MaxSize, 280 _In_z_ _Printf_format_string_ char const* _Format, 281 _In_ struct tm const* _Tm, 282 _In_opt_ _locale_t _Locale 283 ); 284 285 _Check_return_wat_ 286 _ACRTIMP errno_t __cdecl _strdate_s( 287 _Out_writes_(_SizeInBytes) _When_(_SizeInBytes >=9, _Post_readable_size_(9)) char* _Buffer, 288 _In_ size_t _SizeInBytes 289 ); 290 291 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0( 292 errno_t, _strdate_s, 293 _Post_readable_size_(9) char, _Buffer 294 ) 295 296 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0( 297 _Success_(return != 0) char*, __RETURN_POLICY_DST, _ACRTIMP, _strdate, 298 _Out_writes_z_(9), char, _Buffer 299 ) 300 301 _Check_return_wat_ 302 _ACRTIMP errno_t __cdecl _strtime_s( 303 _Out_writes_(_SizeInBytes) _When_(_SizeInBytes >=9, _Post_readable_size_(9)) char* _Buffer, 304 _In_ size_t _SizeInBytes 305 ); 306 307 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0( 308 errno_t, _strtime_s, 309 _Post_readable_size_(9) char, _Buffer 310 ) 311 312 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0( 313 char*, __RETURN_POLICY_DST, _ACRTIMP, _strtime, 314 _Out_writes_z_(9), char, _Buffer 315 ) 316 317 _ACRTIMP __time32_t __cdecl _time32( 318 _Out_opt_ __time32_t* _Time 319 ); 320 321 _ACRTIMP __time64_t __cdecl _time64( 322 _Out_opt_ __time64_t* _Time 323 ); 324 325 _Success_(return != 0) 326 _Check_return_ 327 _ACRTIMP int __cdecl _timespec32_get( 328 _Out_ struct _timespec32* _Ts, 329 _In_ int _Base 330 ); 331 332 _Success_(return != 0) 333 _Check_return_ 334 _ACRTIMP int __cdecl _timespec64_get( 335 _Out_ struct _timespec64* _Ts, 336 _In_ int _Base 337 ); 338 339 340 341 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 342 // 343 // DesktopCRT Time Functions 344 // 345 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 346 #ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP 347 348 _ACRTIMP void __cdecl _tzset(void); 349 350 // The Win32 API GetLocalTime and SetLocalTime should be used instead. 351 _CRT_OBSOLETE(GetLocalTime) 352 _DCRTIMP unsigned __cdecl _getsystime( 353 _Out_ struct tm* _Tm 354 ); 355 356 _CRT_OBSOLETE(SetLocalTime) 357 _DCRTIMP unsigned __cdecl _setsystime( 358 _In_ struct tm* _Tm, 359 _In_ unsigned _Milliseconds 360 ); 361 362 #endif 363 364 365 366 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 367 // 368 // Inline Function Definitions 369 // 370 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 371 #if !defined RC_INVOKED && !defined __midl && !defined _INC_TIME_INL && !defined _CRT_NO_TIME_T 372 373 #ifdef _USE_32BIT_TIME_T 374 375 _Check_return_ _CRT_INSECURE_DEPRECATE(ctime_s) 376 static __inline char* __CRTDECL ctime( 377 _In_ time_t const* const _Time 378 ) 379 { 380 return _ctime32(_Time); 381 } 382 383 _Check_return_ 384 static __inline double __CRTDECL difftime( 385 _In_ time_t const _Time1, 386 _In_ time_t const _Time2 387 ) 388 { 389 return _difftime32(_Time1, _Time2); 390 } 391 392 _Check_return_ _CRT_INSECURE_DEPRECATE(gmtime_s) 393 static __inline struct tm* __CRTDECL gmtime( 394 _In_ time_t const* const _Time 395 ) 396 { 397 return _gmtime32(_Time); 398 } 399 400 _Check_return_ _CRT_INSECURE_DEPRECATE(localtime_s) 401 static __inline struct tm* __CRTDECL localtime( 402 _In_ time_t const* const _Time 403 ) 404 { 405 return _localtime32(_Time); 406 } 407 408 _Check_return_ 409 static __inline time_t __CRTDECL _mkgmtime( 410 _Inout_ struct tm* const _Tm 411 ) 412 { 413 return _mkgmtime32(_Tm); 414 } 415 416 _Check_return_opt_ 417 static __inline time_t __CRTDECL mktime( 418 _Inout_ struct tm* const _Tm 419 ) 420 { 421 return _mktime32(_Tm); 422 } 423 424 static __inline time_t __CRTDECL time( 425 _Out_opt_ time_t* const _Time 426 ) 427 { 428 return _time32(_Time); 429 } 430 431 _Check_return_ 432 static __inline int __CRTDECL timespec_get( 433 _Out_ struct timespec* const _Ts, 434 _In_ int const _Base 435 ) 436 { 437 return _timespec32_get((struct _timespec32*)_Ts, _Base); 438 } 439 440 #if __STDC_WANT_SECURE_LIB__ 441 _Check_return_wat_ 442 static __inline errno_t __CRTDECL ctime_s( 443 _Out_writes_(_SizeInBytes) _Post_readable_size_(26) char* const _Buffer, 444 _In_range_(>=,26) size_t const _SizeInBytes, 445 _In_ time_t const* const _Time 446 ) 447 { 448 return _ctime32_s(_Buffer, _SizeInBytes, _Time); 449 } 450 451 #if _CRT_USE_CONFORMING_ANNEX_K_TIME 452 _Check_return_wat_ 453 static __inline struct tm* __CRTDECL gmtime_s( 454 _In_ time_t const* const _Time, 455 _Out_ struct tm* const _Tm 456 ) 457 { 458 if (_gmtime32_s(_Tm, _Time) == 0) 459 { 460 return _Tm; 461 } 462 return NULL; 463 } 464 465 _Check_return_wat_ 466 static __inline struct tm* __CRTDECL localtime_s( 467 _In_ time_t const* const _Time, 468 _Out_ struct tm* const _Tm 469 ) 470 { 471 if (_localtime32_s(_Tm, _Time) == 0) 472 { 473 return _Tm; 474 } 475 return NULL; 476 } 477 #else // _CRT_USE_CONFORMING_ANNEX_K_TIME 478 _Check_return_wat_ 479 static __inline errno_t __CRTDECL gmtime_s( 480 _Out_ struct tm* const _Tm, 481 _In_ time_t const* const _Time 482 ) 483 { 484 return _gmtime32_s(_Tm, _Time); 485 } 486 487 _Check_return_wat_ 488 static __inline errno_t __CRTDECL localtime_s( 489 _Out_ struct tm* const _Tm, 490 _In_ time_t const* const _Time 491 ) 492 { 493 return _localtime32_s(_Tm, _Time); 494 } 495 #endif // _CRT_USE_CONFORMING_ANNEX_K_TIME 496 #endif 497 498 #else // ^^^ _USE_32BIT_TIME_T ^^^ // vvv !_USE_32BIT_TIME_T vvv 499 500 _Check_return_ _CRT_INSECURE_DEPRECATE(ctime_s) 501 static __inline char* __CRTDECL ctime( 502 _In_ time_t const* const _Time 503 ) 504 { 505 return _ctime64(_Time); 506 } 507 508 _Check_return_ 509 static __inline double __CRTDECL difftime( 510 _In_ time_t const _Time1, 511 _In_ time_t const _Time2 512 ) 513 { 514 return _difftime64(_Time1, _Time2); 515 } 516 517 _Check_return_ _CRT_INSECURE_DEPRECATE(gmtime_s) 518 static __inline struct tm* __CRTDECL gmtime( 519 _In_ time_t const* const _Time) 520 { 521 return _gmtime64(_Time); 522 } 523 524 _CRT_INSECURE_DEPRECATE(localtime_s) 525 static __inline struct tm* __CRTDECL localtime( 526 _In_ time_t const* const _Time 527 ) 528 { 529 return _localtime64(_Time); 530 } 531 532 _Check_return_ 533 static __inline time_t __CRTDECL _mkgmtime( 534 _Inout_ struct tm* const _Tm 535 ) 536 { 537 return _mkgmtime64(_Tm); 538 } 539 540 _Check_return_opt_ 541 static __inline time_t __CRTDECL mktime( 542 _Inout_ struct tm* const _Tm 543 ) 544 { 545 return _mktime64(_Tm); 546 } 547 548 static __inline time_t __CRTDECL time( 549 _Out_opt_ time_t* const _Time 550 ) 551 { 552 return _time64(_Time); 553 } 554 555 _Check_return_ 556 static __inline int __CRTDECL timespec_get( 557 _Out_ struct timespec* const _Ts, 558 _In_ int const _Base 559 ) 560 { 561 return _timespec64_get((struct _timespec64*)_Ts, _Base); 562 } 563 564 #if __STDC_WANT_SECURE_LIB__ 565 _Check_return_wat_ 566 static __inline errno_t __CRTDECL ctime_s( 567 _Out_writes_(_SizeInBytes) _Post_readable_size_(26) char* const _Buffer, 568 _In_range_(>=,26) size_t const _SizeInBytes, 569 _In_ time_t const* const _Time 570 ) 571 { 572 return _ctime64_s(_Buffer, _SizeInBytes, _Time); 573 } 574 575 #if _CRT_USE_CONFORMING_ANNEX_K_TIME 576 _Check_return_wat_ 577 static __inline struct tm* __CRTDECL gmtime_s( 578 _In_ time_t const* const _Time, 579 _Out_ struct tm* const _Tm 580 ) 581 { 582 if (_gmtime64_s(_Tm, _Time) == 0) 583 { 584 return _Tm; 585 } 586 return NULL; 587 } 588 589 _Check_return_wat_ 590 static __inline struct tm* __CRTDECL localtime_s( 591 _In_ time_t const* const _Time, 592 _Out_ struct tm* const _Tm 593 ) 594 { 595 if (_localtime64_s(_Tm, _Time) == 0) 596 { 597 return _Tm; 598 } 599 return NULL; 600 } 601 #else // _CRT_USE_CONFORMING_ANNEX_K_TIME 602 _Check_return_wat_ 603 static __inline errno_t __CRTDECL gmtime_s( 604 _Out_ struct tm* const _Tm, 605 _In_ time_t const* const _Time 606 ) 607 { 608 return _gmtime64_s(_Tm, _Time); 609 } 610 611 _Check_return_wat_ 612 static __inline errno_t __CRTDECL localtime_s( 613 _Out_ struct tm* const _Tm, 614 _In_ time_t const* const _Time 615 ) 616 { 617 return _localtime64_s(_Tm, _Time); 618 } 619 #endif // _CRT_USE_CONFORMING_ANNEX_K_TIME 620 #endif 621 622 #endif // !_USE_32BIT_TIME_T 623 624 #endif 625 626 627 628 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 629 // 630 // Non-ANSI Names for Compatibility 631 // 632 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 633 #if defined(_CRT_INTERNAL_NONSTDC_NAMES) && _CRT_INTERNAL_NONSTDC_NAMES 634 635 #define CLK_TCK CLOCKS_PER_SEC 636 637 #ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP 638 _CRT_NONSTDC_DEPRECATE(_tzset) _ACRTIMP void __cdecl tzset(void); 639 #endif 640 641 #endif // _CRT_INTERNAL_NONSTDC_NAMES 642 643 644 645 _CRT_END_C_HEADER 646 _UCRT_RESTORE_CLANG_WARNINGS 647 #pragma warning(pop) // _UCRT_DISABLED_WARNINGS 648 #endif // _INC_TIME 649