Windows NT 4.0 source code leak
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.

104 lines
2.3 KiB

4 years ago
  1. /***
  2. *systime.c - _getsystime and _setsystime
  3. *
  4. * Copyright (c) 1991-1992, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _getsystime() and _setsystime()
  8. *
  9. *Revision History:
  10. * 08-22-91 BWM Wrote module.
  11. * 05-19-92 DJM ifndef for POSIX build.
  12. * 09-25-92 SKS Use SetLocalTime(), not SetSystemTime().
  13. * Fix bug: daylight flag must be initialized to -1.
  14. * Replace C++ comments with C-style comments
  15. *
  16. *******************************************************************************/
  17. #ifndef _POSIX_
  18. #include <cruntime.h>
  19. #include <oscalls.h>
  20. #include <time.h>
  21. #if !defined(_WIN32_)
  22. #error ERROR - ONLY WIN32 TARGET SUPPORTED!
  23. #endif
  24. /***
  25. *unsigned _getsystime(timestruc, milliseconds) - Get current system time
  26. *
  27. *Purpose:
  28. *
  29. *Entry:
  30.  struct tm * ptm - time structure
  31. *
  32. *Exit:
  33. * milliseconds of current time
  34. *
  35. *Exceptions:
  36. *
  37. *******************************************************************************/
  38. unsigned _CALLTYPE1 _getsystime(struct tm * ptm)
  39. {
  40. SYSTEMTIME st;
  41. GetLocalTime(&st);
  42. ptm->tm_isdst = -1; /* mktime() computes whether this is */
  43. /* during Standard or Daylight time. */
  44. ptm->tm_sec = (int)st.wSecond;
  45. ptm->tm_min = (int)st.wMinute;
  46. ptm->tm_hour = (int)st.wHour;
  47. ptm->tm_mday = (int)st.wDay;
  48. ptm->tm_mon = (int)st.wMonth - 1;
  49. ptm->tm_year = (int)st.wYear - 1900;
  50. ptm->tm_wday = (int)st.wDayOfWeek;
  51. /* Normalize uninitialized fields */
  52. mktime(ptm);
  53. return (st.wMilliseconds);
  54. }
  55. /***
  56. *unsigned _setsystime(timestruc, milliseconds) - Set new system time
  57. *
  58. *Purpose:
  59. *
  60. *Entry:
  61. * struct tm * ptm - time structure
  62. * unsigned milliseconds - milliseconds of current time
  63. *
  64. *Exit:
  65. * 0 if succeeds
  66. * system error if fails
  67. *
  68. *Exceptions:
  69. *
  70. *******************************************************************************/
  71. unsigned _CALLTYPE1 _setsystime(struct tm * ptm, unsigned uMilliseconds)
  72. {
  73. SYSTEMTIME st;
  74. /* Normalize uninitialized fields */
  75. mktime(ptm);
  76. st.wYear = (WORD)(ptm->tm_year + 1900);
  77. st.wMonth = (WORD)(ptm->tm_mon + 1);
  78. st.wDay = (WORD)ptm->tm_mday;
  79. st.wHour = (WORD)(ptm->tm_hour);
  80. st.wMinute = (WORD)ptm->tm_min;
  81. st.wSecond = (WORD)ptm->tm_sec;
  82. st.wMilliseconds = (WORD)uMilliseconds;
  83. if (!SetLocalTime(&st)) {
  84. return ((int)GetLastError());
  85. }
  86. return (0);
  87. }
  88. #endif /* _POSIX_ */