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.

171 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. rtl.c
  5. Abstract:
  6. All routines are copied from NT sources tree (NTOS\rtl)
  7. Author:
  8. Rong Chen [RONGC] 26-Oct-1998
  9. Environment:
  10. Pure utility routine
  11. --*/
  12. #define _NTSYSTEM_ 1 // see ntdef.h. We can't use DECLSPEC_IMPORT here
  13. #include <nt.h>
  14. #include <ntdef.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <string.h>
  18. #include <windows.h>
  19. NTSYSAPI NTSTATUS NTAPI
  20. RtlInitializeCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
  21. {
  22. // HACK - Win9x might go nuts as we can't check error return (who cares?)
  23. //
  24. InitializeCriticalSection(CriticalSection);
  25. return STATUS_SUCCESS;
  26. }
  27. NTSYSAPI NTSTATUS NTAPI
  28. RtlDeleteCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
  29. {
  30. DeleteCriticalSection(CriticalSection);
  31. return STATUS_SUCCESS;
  32. }
  33. NTSYSAPI VOID NTAPI
  34. RtlInitAnsiString(
  35. OUT PANSI_STRING DestinationString,
  36. IN PCSZ SourceString OPTIONAL
  37. )
  38. /*++
  39. Routine Description:
  40. The RtlInitAnsiString function initializes an NT counted string.
  41. The DestinationString is initialized to point to the SourceString
  42. and the Length and MaximumLength fields of DestinationString are
  43. initialized to the length of the SourceString, which is zero if
  44. SourceString is not specified.
  45. Arguments:
  46. DestinationString - Pointer to the counted string to initialize
  47. SourceString - Optional pointer to a null terminated string that
  48. the counted string is to point to.
  49. Return Value:
  50. None.
  51. --*/
  52. {
  53. ULONG Length;
  54. DestinationString->Buffer = (PCHAR)SourceString;
  55. if (ARGUMENT_PRESENT( SourceString )) {
  56. Length = strlen(SourceString);
  57. DestinationString->Length = (USHORT)Length;
  58. DestinationString->MaximumLength = (USHORT)(Length+1);
  59. }
  60. else {
  61. DestinationString->Length = 0;
  62. DestinationString->MaximumLength = 0;
  63. }
  64. }
  65. LARGE_INTEGER SecondsToStartOf1980 = {0xc8df3700, 0x00000002};
  66. LARGE_INTEGER Magic10000000 = {0xe57a42bd, 0xd6bf94d5};
  67. #define SHIFT10000000 23
  68. #define Convert100nsToSeconds(LARGE_INTEGER) ( \
  69. RtlExtendedMagicDivide( (LARGE_INTEGER), Magic10000000, SHIFT10000000 ) \
  70. )
  71. NTSYSAPI BOOLEAN NTAPI
  72. RtlTimeToSecondsSince1980 (
  73. IN PLARGE_INTEGER Time,
  74. OUT PULONG ElapsedSeconds
  75. )
  76. /*++
  77. Routine Description:
  78. This routine converts an input 64-bit NT Time variable to the
  79. number of seconds since the start of 1980. The NT time must be
  80. within the range 1980 to around 2115.
  81. Arguments:
  82. Time - Supplies the Time to convert from
  83. ElapsedSeconds - Receives the number of seconds since the start of 1980
  84. denoted by Time
  85. Return Value:
  86. BOOLEAN - TRUE if the input Time is within a range expressible by
  87. ElapsedSeconds and FALSE otherwise
  88. --*/
  89. {
  90. LARGE_INTEGER Seconds;
  91. //
  92. // First convert time to seconds since 1601
  93. //
  94. Seconds = Convert100nsToSeconds( *(PLARGE_INTEGER)Time );
  95. //
  96. // Then subtract the number of seconds from 1601 to 1980.
  97. //
  98. Seconds.QuadPart = Seconds.QuadPart - SecondsToStartOf1980.QuadPart;
  99. //
  100. // If the results is negative then the date was before 1980 or if
  101. // the results is greater than a ulong then its too far in the
  102. // future so we return FALSE
  103. //
  104. if (Seconds.HighPart != 0) {
  105. return FALSE;
  106. }
  107. //
  108. // Otherwise we have the answer
  109. //
  110. *ElapsedSeconds = Seconds.LowPart;
  111. //
  112. // And return to our caller
  113. //
  114. return TRUE;
  115. }