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.

268 lines
4.6 KiB

  1. //
  2. // REGMISC.C
  3. //
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. #include "pch.h"
  7. //
  8. // RgChecksum
  9. //
  10. DWORD
  11. INTERNAL
  12. RgChecksum(
  13. LPVOID lpBuffer,
  14. UINT ByteCount
  15. )
  16. {
  17. LPDWORD lpdwBuffer;
  18. DWORD Checksum;
  19. lpdwBuffer = (LPDWORD) lpBuffer;
  20. ByteCount >>= 2;
  21. Checksum = 0;
  22. while (ByteCount) {
  23. Checksum += *lpdwBuffer++;
  24. ByteCount--;
  25. }
  26. return Checksum;
  27. }
  28. //
  29. // RgHashString
  30. //
  31. // Simple hash computation of a counted string. All characters less than 0x80
  32. // 0x80 and all DBCS characters are added up.
  33. //
  34. DWORD
  35. INTERNAL
  36. RgHashString(
  37. LPCSTR lpString,
  38. UINT Length
  39. )
  40. {
  41. DWORD Hash;
  42. UINT Byte;
  43. Hash = 0;
  44. while (Length) {
  45. Byte = *((LPBYTE) lpString)++;
  46. if (IsDBCSLeadByte((BYTE) Byte)) {
  47. Hash += Byte;
  48. Length--;
  49. Hash += (*((LPBYTE) lpString)++);
  50. }
  51. else if (Byte < 0x80)
  52. Hash += ToUpper(Byte);
  53. Length--;
  54. }
  55. return Hash;
  56. }
  57. //
  58. // RgStrCmpNI
  59. //
  60. int
  61. INTERNAL
  62. RgStrCmpNI(
  63. LPCSTR lpString1,
  64. LPCSTR lpString2,
  65. UINT Length
  66. )
  67. {
  68. int Difference;
  69. while (Length) {
  70. if (IsDBCSLeadByte(*lpString1)) {
  71. if ((Difference = *lpString1 - *lpString2) != 0)
  72. return Difference;
  73. lpString1++;
  74. lpString2++;
  75. Length--;
  76. if (Length == 0)
  77. break;
  78. if ((Difference = *lpString1 - *lpString2) != 0)
  79. return Difference;
  80. }
  81. else if ((Difference = (int) ToUpper(*lpString1) -
  82. (int) ToUpper(*lpString2)) != 0)
  83. return Difference;
  84. lpString1++;
  85. lpString2++;
  86. Length--;
  87. }
  88. return 0;
  89. }
  90. //
  91. // RgCopyFileBytes
  92. //
  93. // Copies the specified number of bytes from the source to the destination
  94. // starting at the specified offsets in each file.
  95. //
  96. int
  97. INTERNAL
  98. RgCopyFileBytes(
  99. HFILE hSourceFile,
  100. LONG SourceOffset,
  101. HFILE hDestinationFile,
  102. LONG DestinationOffset,
  103. DWORD cbSize
  104. )
  105. {
  106. int ErrorCode;
  107. LPVOID lpWorkBuffer;
  108. UINT cbBytesThisPass;
  109. ASSERT(hSourceFile != HFILE_ERROR);
  110. ASSERT(hDestinationFile != HFILE_ERROR);
  111. ErrorCode = ERROR_REGISTRY_IO_FAILED; // Assume this error code
  112. lpWorkBuffer = RgLockWorkBuffer();
  113. if (!RgSeekFile(hSourceFile, SourceOffset))
  114. goto ErrorUnlockWorkBuffer;
  115. if (!RgSeekFile(hDestinationFile, DestinationOffset))
  116. goto ErrorUnlockWorkBuffer;
  117. while (cbSize) {
  118. cbBytesThisPass = (UINT) ((DWORD) min(cbSize, SIZEOF_WORK_BUFFER));
  119. if (!RgReadFile(hSourceFile, lpWorkBuffer, cbBytesThisPass)) {
  120. TRAP();
  121. goto ErrorUnlockWorkBuffer;
  122. }
  123. RgYield();
  124. if (!RgWriteFile(hDestinationFile, lpWorkBuffer, cbBytesThisPass)) {
  125. TRAP();
  126. goto ErrorUnlockWorkBuffer;
  127. }
  128. RgYield();
  129. cbSize -= cbBytesThisPass;
  130. }
  131. ErrorCode = ERROR_SUCCESS;
  132. ErrorUnlockWorkBuffer:
  133. RgUnlockWorkBuffer(lpWorkBuffer);
  134. return ErrorCode;
  135. }
  136. //
  137. // RgGenerateAltFileName
  138. //
  139. BOOL
  140. INTERNAL
  141. RgGenerateAltFileName(
  142. LPCSTR lpFileName,
  143. LPSTR lpAltFileName,
  144. char ExtensionChar
  145. )
  146. {
  147. LPSTR lpString;
  148. StrCpy(lpAltFileName, lpFileName);
  149. lpString = lpAltFileName + StrLen(lpAltFileName) - 3;
  150. *lpString++ = '~';
  151. *lpString++ = '~';
  152. *lpString = ExtensionChar;
  153. return TRUE;
  154. }
  155. #ifdef VXD
  156. #pragma VxD_RARE_CODE_SEG
  157. //
  158. // RgCopyFile
  159. //
  160. int
  161. INTERNAL
  162. RgCopyFile(
  163. LPCSTR lpSourceFile,
  164. LPCSTR lpDestinationFile
  165. )
  166. {
  167. int ErrorCode;
  168. HFILE hSourceFile;
  169. HFILE hDestinationFile;
  170. DWORD FileSize;
  171. ErrorCode = ERROR_REGISTRY_IO_FAILED; // Assume this error code
  172. if ((hSourceFile = RgOpenFile(lpSourceFile, OF_READ)) != HFILE_ERROR) {
  173. if ((FileSize = RgGetFileSize(hSourceFile)) != (DWORD) -1) {
  174. if ((hDestinationFile = RgCreateFile(lpDestinationFile)) !=
  175. HFILE_ERROR) {
  176. ErrorCode = RgCopyFileBytes(hSourceFile, 0, hDestinationFile, 0,
  177. FileSize);
  178. RgCloseFile(hDestinationFile);
  179. if (ErrorCode != ERROR_SUCCESS)
  180. RgDeleteFile(lpDestinationFile);
  181. }
  182. }
  183. RgCloseFile(hSourceFile);
  184. }
  185. return ErrorCode;
  186. }
  187. #endif // VXD