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.

247 lines
6.4 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  3. /* Houston, Texas */
  4. /*===========================================================================*/
  5. #include "winrev.h"
  6. #include <windows.h>
  7. #include "port1632.h"
  8. #include "dcrc.h"
  9. #include "dynacomm.h"
  10. #include <io.h> /* added for get_osfhandle crt -sdj*/
  11. static INT dayTable[2][13] =
  12. {
  13. {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
  14. {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
  15. };
  16. /*-------------- >>> Routines Specific to Windows Start Here <<< ------------*/
  17. /*---------------------------------------------------------------------------*/
  18. /* getDateTime() - Set a long int to number of elapsed seconds since [scf] */
  19. /* January 1, 1904. (Mimic the MAC funtion) */
  20. /*---------------------------------------------------------------------------*/
  21. VOID getDateTime (LONG *elapsedSecs)
  22. {
  23. DOSTIME present;
  24. readDateTime (&present);
  25. date2secs (&present, elapsedSecs);
  26. }
  27. /*---------------------------------------------------------------------------*/
  28. /* date2secs() - Convert a date found in DOSTIME struct to elapsed seconds */
  29. /* since January 1, 1904. (Mimic the MAC) [scf] */
  30. /*---------------------------------------------------------------------------*/
  31. VOID date2secs (DOSTIME *date, LONG *elapsedSecs)
  32. {
  33. #ifdef ORGCODE
  34. INT year;
  35. INT month;
  36. INT leapYear;
  37. #else
  38. WORD year;
  39. WORD month;
  40. WORD leapYear;
  41. #endif
  42. *elapsedSecs = 0l;
  43. for (year = 1904; year < date->yy; year++)
  44. {
  45. leapYear = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
  46. for (month = 1; month <= 12; month++)
  47. *elapsedSecs += (LONG) dayTable[leapYear][month] * SECS_IN_A_DAY;
  48. }
  49. leapYear = date->yy % 4 == 0 && date->yy % 100 != 0 || date->yy % 400 == 0;
  50. for (month = 1; month < date->mm; month++)
  51. *elapsedSecs += (LONG) dayTable[leapYear][month] * SECS_IN_A_DAY;
  52. *elapsedSecs += (LONG) (date->dd-1) *SECS_IN_A_DAY;
  53. *elapsedSecs += (LONG) date->hour *60*60;
  54. *elapsedSecs += (LONG) date->minute * 60;
  55. *elapsedSecs += (LONG) date->second;
  56. }
  57. /*---------------------------------------------------------------------------*/
  58. /* secs2date() - Sets DOSTIME struct (except dayOfWeek) according to the */
  59. /* number of elapsed seconds since January 1, 1904. [scf] */
  60. /*---------------------------------------------------------------------------*/
  61. VOID secs2date (LONG secs, DOSTIME *date)
  62. {
  63. register INT year;
  64. INT month;
  65. INT day;
  66. INT hour;
  67. INT minute;
  68. INT leapYear;
  69. INT daysPerYear[2];
  70. DWORD usecs;
  71. daysPerYear[0] = DAYS_IN_A_YEAR;
  72. daysPerYear[1] = DAYS_IN_A_YEAR + (leapYear = 1);
  73. usecs = (DWORD) secs;
  74. year = 1904;
  75. while (usecs >= (DWORD) daysPerYear[leapYear] * SECS_IN_A_DAY)
  76. {
  77. usecs -= (DWORD) daysPerYear[leapYear] * SECS_IN_A_DAY;
  78. year++;
  79. leapYear = (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 1 : 0;
  80. }
  81. secs = (LONG) usecs;
  82. for (month = 1; secs >= (LONG) dayTable[leapYear][month] *SECS_IN_A_DAY;
  83. month++)
  84. secs -= (LONG) dayTable[leapYear][month] *SECS_IN_A_DAY;
  85. for (day = 1; secs >= SECS_IN_A_DAY; day++)
  86. secs -= SECS_IN_A_DAY;
  87. for (hour = 0; secs >= 60*60; hour++)
  88. secs -= 60 * 60;
  89. for (minute = 0; secs >= 60; minute++)
  90. secs -= 60;
  91. date->yy = (WORD)year;
  92. date->mm = (WORD)month;
  93. date->dd = (WORD)day;
  94. date->dayOfWeek = DONTCARE;
  95. date->hour = (WORD)hour;
  96. date->minute = (WORD)minute;
  97. date->second = (INT) secs;
  98. }
  99. VOID readDateTime(DOSTIME *pDosTime)
  100. {
  101. SYSTEMTIME NtSystemTime;
  102. /************
  103. typedef struct _SYSTEMTIME {
  104. WORD wYear;
  105. WORD wMonth;
  106. WORD wDayOfWeek;
  107. WORD wDay;
  108. WORD wHour;
  109. WORD wMinute;
  110. WORD wSecond;
  111. WORD wMilliseconds;
  112. } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
  113. ***************/
  114. /********************
  115. typedef
  116. struct {
  117. WORD hour;
  118. WORD minute;
  119. WORD second;
  120. WORD dayOfWeek;
  121. WORD mm;
  122. WORD dd;
  123. WORD yy;
  124. } DOSTIME;
  125. *************************/
  126. DEBOUT("readDateTime:%s\n","Calling GetSystemTime()");
  127. // GetSystemTime(&NtSystemTime);
  128. // -sdj this time will not make sense, have to use
  129. // -sdj GetLocalTime instead, this is due to Zone,Bias,UTC and all
  130. // -sdj the other complicated things I have to learn sometime!
  131. GetLocalTime(&NtSystemTime);
  132. pDosTime->hour = NtSystemTime.wHour;
  133. pDosTime->minute = NtSystemTime.wMinute;
  134. pDosTime->second = NtSystemTime.wSecond;
  135. pDosTime->dayOfWeek = NtSystemTime.wDayOfWeek;
  136. pDosTime->mm = NtSystemTime.wMonth;
  137. pDosTime->dd = NtSystemTime.wDay;
  138. pDosTime->yy = NtSystemTime.wYear;
  139. }
  140. VOID getFileDate(DOSTIME *pDosTime, int fh)
  141. {
  142. //BOOL bRc;
  143. //HANDLE hFile;
  144. //FILETIME CrTime,AccTime,WrTime;
  145. SYSTEMTIME SysTime;
  146. DEBOUT("getFileDate: UNDEF!! %s\n","converting the crt fh to os fh using get_osfhandle");
  147. /* hFile = get_osfhandle(fh); */
  148. DEBOUT("getFileDate: UNDEF!! got os fh as %lx\n", hFile);
  149. /* DEBOUT("getFileDate: %s\n","calling GetFileTime , for LastWrTime"); */
  150. /* bRc = GetFileTime(hFile,&CrTime,&AccTime,&WrTime); */
  151. /* DEBOUT("getFileDate: GetFileTime Rc= %lx\n conv to SystemTime",bRc); */
  152. /* bRc = FileTimeToSystemTime(&WrTime,&SysTime); */
  153. /* DEBOUT("getFileDate: FileTimeToSystemTime Rc= %lx\n store in DosTime",bRc); */
  154. DEBOUT("getFileDate: HACK %s\n","calling sys time instead of filetime for now");
  155. GetSystemTime(&SysTime);
  156. pDosTime->hour = SysTime.wHour;
  157. pDosTime->minute = SysTime.wMinute;
  158. pDosTime->second = SysTime.wSecond;
  159. pDosTime->dayOfWeek = SysTime.wDayOfWeek;
  160. pDosTime->mm = SysTime.wMonth;
  161. pDosTime->dd = SysTime.wDay;
  162. pDosTime->yy = SysTime.wYear;
  163. }
  164. #ifdef OLDCODE
  165. VOID lmovmem(LPSTR lpsrc,LPSTR lpdst, WORD wCount)
  166. {
  167. LPBYTE TmpSrc,TmpDst;
  168. WORD i;
  169. TmpSrc = (LPBYTE)lpsrc;
  170. TmpDst = (LPBYTE)lpdst;
  171. for (i=0; i< wCount; i++)
  172. {
  173. *TmpDst = *TmpSrc;
  174. TmpDst++;TmpSrc++;
  175. }
  176. }
  177. VOID lsetmem(LPSTR str,BYTE ch,WORD wCount)
  178. {
  179. WORD i;
  180. LPSTR tmp;
  181. tmp = str;
  182. for (i=0; i < wCount; i++)
  183. {
  184. *tmp = ch;
  185. tmp++;
  186. }
  187. }
  188. #endif