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.

71 lines
1.8 KiB

  1. /***
  2. *time64.c - get current system time
  3. *
  4. * Copyright (c) 1998-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _time64() - gets the current system time and converts it to
  8. * internal (__time64_t) format time.
  9. *
  10. *Revision History:
  11. * 05-20-98 GJF Created.
  12. *
  13. *******************************************************************************/
  14. #include <cruntime.h>
  15. #include <time.h>
  16. #include <internal.h>
  17. #include <windows.h>
  18. /*
  19. * Number of 100 nanosecond units from 1/1/1601 to 1/1/1970
  20. */
  21. #define EPOCH_BIAS 116444736000000000i64
  22. /*
  23. * Union to facilitate converting from FILETIME to unsigned __int64
  24. */
  25. typedef union {
  26. unsigned __int64 ft_scalar;
  27. FILETIME ft_struct;
  28. } FT;
  29. /***
  30. *__time64_t _time64(timeptr) - Get current system time and convert to a
  31. * __time64_t value.
  32. *
  33. *Purpose:
  34. * Gets the current date and time and stores it in internal 64-bit format
  35. * (__time64_t). The time is returned and stored via the pointer passed in
  36. * timeptr. If timeptr == NULL, the time is only returned, not stored in
  37. * *timeptr. The internal (__time64_t) format is the number of seconds
  38. * since 00:00:00, Jan 1 1970 (UTC).
  39. *
  40. *Entry:
  41. * __time64_t *timeptr - pointer to long to store time in.
  42. *
  43. *Exit:
  44. * returns the current time.
  45. *
  46. *Exceptions:
  47. *
  48. *******************************************************************************/
  49. __time64_t __cdecl _time64 (
  50. __time64_t *timeptr
  51. )
  52. {
  53. __time64_t tim;
  54. FT nt_time;
  55. GetSystemTimeAsFileTime( &(nt_time.ft_struct) );
  56. tim = (__time64_t)((nt_time.ft_scalar - EPOCH_BIAS) / 10000000i64);
  57. if (timeptr)
  58. *timeptr = tim; /* store time if requested */
  59. return tim;
  60. }