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.

212 lines
4.9 KiB

  1. // ############################################################################
  2. #include "pch.hpp"
  3. #ifdef WIN16
  4. #include <win16def.h>
  5. #include <malloc.h>
  6. #include <string.h>
  7. #endif
  8. extern "C" {
  9. HINSTANCE g_hInstDll; // instance for this DLL
  10. }
  11. #ifdef WIN16
  12. int CALLBACK LibMain(HINSTANCE hinst,
  13. WORD wDataSeg,
  14. WORD cbHeap,
  15. LPSTR lpszCmdLine )
  16. {
  17. g_hInstDll = hinst;
  18. return TRUE;
  19. }
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Function: PrivateMalloc()
  23. //
  24. // Synopsis: Allocate and initialize memory
  25. //
  26. // Arguments: [size - Size of memory block to be allocated]
  27. //
  28. // Returns: pointer to memory block if successful
  29. // NULL otherwise
  30. //
  31. // History: 7/9/96 VetriV Created
  32. //
  33. //----------------------------------------------------------------------------
  34. void far *PrivateMalloc(size_t size)
  35. {
  36. void far * ReturnValue = NULL;
  37. ReturnValue = malloc(size);
  38. if (NULL != ReturnValue)
  39. memset(ReturnValue, 0, size);
  40. return ReturnValue;
  41. }
  42. //+---------------------------------------------------------------------------
  43. //
  44. // Function: PrivateReAlloc()
  45. //
  46. // Synopsis: Reallocate memory
  47. //
  48. // Arguments: [lpBlock - Block to be reallocated ]
  49. // [size - Size of memory block to be allocated]
  50. //
  51. // Returns: pointer to memory block if successful
  52. // NULL otherwise
  53. //
  54. // History: 7/25/96 ValdonB Created
  55. //
  56. //----------------------------------------------------------------------------
  57. void far *PrivateReAlloc(void far *lpBlock, size_t size)
  58. {
  59. void far *lpRetBlock;
  60. lpRetBlock = PrivateMalloc(size);
  61. if (NULL == lpRetBlock)
  62. return NULL;
  63. if (NULL != lpBlock)
  64. {
  65. size_t OldBlockSize, MoveSize;
  66. OldBlockSize = _msize(lpBlock);
  67. MoveSize = min(OldBlockSize, size);
  68. memmove(lpRetBlock, lpBlock, MoveSize);
  69. PrivateFree(lpBlock);
  70. }
  71. return lpRetBlock;
  72. }
  73. //+---------------------------------------------------------------------------
  74. //
  75. // Function: PrivateFree
  76. //
  77. // Synopsis: Free a block of memory
  78. //
  79. // Arguments: [lpBlock - Block to be freed]
  80. //
  81. // Returns: Nothing
  82. //
  83. // History: 7/9/96 VetriV Created
  84. //
  85. //----------------------------------------------------------------------------
  86. void PrivateFree(void far *lpBlock)
  87. {
  88. free(lpBlock);
  89. }
  90. //+---------------------------------------------------------------------------
  91. //
  92. // Function: SearchPath()
  93. //
  94. // Synopsis: Searchs for the specified file in the given path
  95. //
  96. // Arguments: [lpPath - Address of search path]
  97. // [lpFileName - Address of filename]
  98. // [lpExtension - Address of Extension]
  99. // [nBufferLength - size, in characters, of buffer]
  100. // [lpBuffer - address of buffer for found filename]
  101. // [lpFilePart - address of pointer to file component]
  102. //
  103. // Returns: Length of string copied to buffer (not including terminating
  104. // NULL character) if successful
  105. // 0 otherwise
  106. //
  107. // History: 7/9/96 VetriV Created
  108. //
  109. //----------------------------------------------------------------------------
  110. DWORD SearchPath(LPCTSTR lpPath,LPCTSTR lpFileName, LPCTSTR lpExtension,
  111. DWORD nBufferLength, LPTSTR lpBuffer, LPTSTR *lpFilePart)
  112. {
  113. BOOL bUseExtension = FALSE, bPathContainsFileName = FALSE;
  114. DWORD dwRequiredLength;
  115. LPSTR lpszPath = lpPath;
  116. char szFileName[MAX_PATH+1];
  117. OFSTRUCT OpenBuf;
  118. // Check if extension should be used
  119. //
  120. if ((NULL != lpExtension) && !strchr(lpFileName, '.'))
  121. bUseExtension = TRUE;
  122. //
  123. // Form Filename
  124. //
  125. lstrcpy(szFileName, lpFileName);
  126. if (bUseExtension)
  127. lstrcat(szFileName, lpExtension);
  128. //
  129. // If search path is NULL, then try to OpenFile using OF_SEARCH flag
  130. // get the full path in OpenBuf struct
  131. //
  132. if (NULL == lpszPath)
  133. {
  134. if (HFILE_ERROR != OpenFile(szFileName, &OpenBuf, OF_EXIST | OF_SEARCH))
  135. {
  136. //
  137. // This path contains the file name also
  138. //
  139. lpszPath = &OpenBuf.szPathName[0];
  140. bPathContainsFileName = TRUE;
  141. }
  142. else
  143. return 0;
  144. }
  145. //
  146. // Check if output buffer length is sufficient
  147. //
  148. dwRequiredLength = lstrlen(lpszPath) +
  149. (bPathContainsFileName ? 0 :lstrlen(szFileName)) + 1;
  150. if (nBufferLength < dwRequiredLength)
  151. return 0;
  152. //
  153. // Copy the full name to buffer
  154. //
  155. if (bPathContainsFileName)
  156. lstrcpy(lpBuffer, lpszPath);
  157. else
  158. wsprintf(lpBuffer, "%s\\%s", lpszPath, szFileName);
  159. //
  160. // Do not include the terminating null character in return length
  161. //
  162. return dwRequiredLength - 1;
  163. }
  164. #else // WIN16
  165. extern "C" BOOL WINAPI PHBKDllEntryPoint(
  166. HINSTANCE hinstDLL, // handle to DLL module
  167. DWORD fdwReason, // reason for calling function
  168. LPVOID lpvReserved // reserved
  169. )
  170. {
  171. if (fdwReason == DLL_PROCESS_ATTACH)
  172. g_hInstDll = hinstDLL;
  173. return TRUE;
  174. }
  175. #endif // WIN16