Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.0 KiB

  1. /***
  2. *ftime64.c - return system time
  3. *
  4. * Copyright (c) 1998-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Returns the system date/time in a structure form.
  8. *
  9. *Revision History:
  10. * 05-22-98 GJF Created.
  11. *
  12. *******************************************************************************/
  13. #include <cruntime.h>
  14. #include <sys/types.h>
  15. #include <sys/timeb.h>
  16. #include <time.h>
  17. #include <msdos.h>
  18. #include <dos.h>
  19. #include <stdlib.h>
  20. #include <windows.h>
  21. #include <internal.h>
  22. /*
  23. * Number of 100 nanosecond units from 1/1/1601 to 1/1/1970
  24. */
  25. #define EPOCH_BIAS 116444736000000000i64
  26. /*
  27. * Union to facilitate converting from FILETIME to unsigned __int64
  28. */
  29. typedef union {
  30. unsigned __int64 ft_scalar;
  31. FILETIME ft_struct;
  32. } FT;
  33. /*
  34. * Cache for the minutes count for with DST status was last assessed
  35. */
  36. static __time64_t elapsed_minutes_cache;
  37. /*
  38. * Three values of dstflag_cache
  39. */
  40. #define DAYLIGHT_TIME 1
  41. #define STANDARD_TIME 0
  42. #define UNKNOWN_TIME -1
  43. /*
  44. * Cache for the last determined DST status
  45. */
  46. static int dstflag_cache = UNKNOWN_TIME;
  47. /***
  48. *void _ftime(timeptr) - return DOS time in a structure
  49. *
  50. *Purpose:
  51. * returns the current DOS time in a struct timeb structure
  52. *
  53. *Entry:
  54. * struct timeb *timeptr - structure to fill in with time
  55. *
  56. *Exit:
  57. * no return value -- fills in structure
  58. *
  59. *Exceptions:
  60. *
  61. *******************************************************************************/
  62. _CRTIMP void __cdecl _ftime64 (
  63. struct __timeb64 *tp
  64. )
  65. {
  66. FT nt_time;
  67. __time64_t t;
  68. TIME_ZONE_INFORMATION tzinfo;
  69. DWORD tzstate;
  70. __tzset();
  71. tp->timezone = (short)(_timezone / 60);
  72. GetSystemTimeAsFileTime( &(nt_time.ft_struct) );
  73. /*
  74. * Obtain the current DST status. Note the status is cached and only
  75. * updated once per minute, if necessary.
  76. */
  77. if ( (t = (__time64_t)(nt_time.ft_scalar / 600000000i64))
  78. != elapsed_minutes_cache )
  79. {
  80. if ( (tzstate = GetTimeZoneInformation( &tzinfo )) != 0xFFFFFFFF )
  81. {
  82. /*
  83. * Must be very careful in determining whether or not DST is
  84. * really in effect.
  85. */
  86. if ( (tzstate == TIME_ZONE_ID_DAYLIGHT) &&
  87. (tzinfo.DaylightDate.wMonth != 0) &&
  88. (tzinfo.DaylightBias != 0) )
  89. dstflag_cache = DAYLIGHT_TIME;
  90. else
  91. /*
  92. * When in doubt, assume standard time
  93. */
  94. dstflag_cache = STANDARD_TIME;
  95. }
  96. else
  97. dstflag_cache = UNKNOWN_TIME;
  98. elapsed_minutes_cache = t;
  99. }
  100. tp->dstflag = (short)dstflag_cache;
  101. tp->millitm = (unsigned short)((nt_time.ft_scalar / 10000i64) %
  102. 1000i64);
  103. tp->time = (__time64_t)((nt_time.ft_scalar - EPOCH_BIAS) / 10000000i64);
  104. }