Leaked source code of windows server 2003
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.

99 lines
3.4 KiB

  1. /***
  2. *time.c - get current system time
  3. *
  4. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines time() - gets the current system time and converts it to
  8. * internal (time_t) format time.
  9. *
  10. *Revision History:
  11. * 06-07-89 PHG Module created, based on asm version
  12. * 03-20-90 GJF Made calling type _CALLTYPE1, added #include
  13. * <cruntime.h> and fixed the copyright. Also, cleaned
  14. * up the formatting a bit.
  15. * 07-25-90 SBM Removed '32' from API names
  16. * 10-04-90 GJF New-style function declarator.
  17. * 12-04-90 SRW Changed to include <oscalls.h> instead of <doscalls.h>
  18. * 12-06-90 SRW Added _CRUISER_ and _WIN32 conditionals.
  19. * 05-19-92 DJM ifndef for POSIX build.
  20. * 03-30-93 GJF Replaced dtoxtime() reference by __gmtotime_t. Also
  21. * purged Cruiser support.
  22. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  23. * 07-21-93 GJF Converted from using __gmtotime_t and GetSystemTime,
  24. * to using __loctotime_t and GetLocalTime.
  25. * 02-13-95 GJF Merged in Mac version.
  26. * 09-22-95 GJF Obtain and use Win32's DST flag.
  27. * 10-24-95 GJF GetTimeZoneInformation is *EXPENSIVE* on NT. Use a
  28. * cache to minimize calls to this API.
  29. * 12-13-95 GJF Optimization above wasn't working because I had
  30. * switched gmt and gmt_cache (thanks PhilipLu!)
  31. * 10-11-96 GJF More elaborate test needed to determine if current
  32. * time is a DST time.
  33. * 05-20-98 GJF Get UTC time directly from the system.
  34. * 05-17-99 PML Remove all Macintosh support.
  35. *
  36. *******************************************************************************/
  37. #ifndef _POSIX_
  38. #include <cruntime.h>
  39. #include <time.h>
  40. #include <internal.h>
  41. #include <windows.h>
  42. /*
  43. * Number of 100 nanosecond units from 1/1/1601 to 1/1/1970
  44. */
  45. #define EPOCH_BIAS 116444736000000000i64
  46. /*
  47. * Union to facilitate converting from FILETIME to unsigned __int64
  48. */
  49. typedef union {
  50. unsigned __int64 ft_scalar;
  51. FILETIME ft_struct;
  52. } FT;
  53. /***
  54. *time_t time(timeptr) - Get current system time and convert to time_t value.
  55. *
  56. *Purpose:
  57. * Gets the current date and time and stores it in internal (time_t)
  58. * format. The time is returned and stored via the pointer passed in
  59. * timeptr. If timeptr == NULL, the time is only returned, not stored in
  60. * *timeptr. The internal (time_t) format is the number of seconds since
  61. * 00:00:00, Jan 1 1970 (UTC).
  62. *
  63. * Note: We cannot use GetSystemTime since its return is ambiguous. In
  64. * Windows NT, in return UTC. In Win32S, probably also Win32C, it
  65. * returns local time.
  66. *
  67. *Entry:
  68. * time_t *timeptr - pointer to long to store time in.
  69. *
  70. *Exit:
  71. * returns the current time.
  72. *
  73. *Exceptions:
  74. *
  75. *******************************************************************************/
  76. time_t __cdecl time (
  77. time_t *timeptr
  78. )
  79. {
  80. time_t tim;
  81. FT nt_time;
  82. GetSystemTimeAsFileTime( &(nt_time.ft_struct) );
  83. tim = (time_t)((nt_time.ft_scalar - EPOCH_BIAS) / 10000000i64);
  84. if (timeptr)
  85. *timeptr = tim; /* store time if requested */
  86. return tim;
  87. }
  88. #endif /* _POSIX_ */