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.

252 lines
8.7 KiB

4 years ago
  1. /****************************************************************************
  2. *
  3. * UTIL.C : Part of the FASTMAC TOOL-KIT (FTK)
  4. *
  5. * THE UTILITIES MODULE
  6. *
  7. * Copyright (c) Madge Networks Ltd. 1991-1994
  8. *
  9. * COMPANY CONFIDENTIAL
  10. *
  11. *****************************************************************************
  12. *
  13. * The UTIL.C utilities module provides a range of general purpose
  14. * utilities that are used throughout the FTK. These routines provide such
  15. * functions as the ability to copy strings, clear memory, byte swap node
  16. * addresses and caculate the minimum of three values.
  17. *
  18. ****************************************************************************/
  19. /*---------------------------------------------------------------------------
  20. |
  21. | DEFINITIONS
  22. |
  23. ---------------------------------------------------------------------------*/
  24. #include "ftk_defs.h"
  25. /*---------------------------------------------------------------------------
  26. |
  27. | MODULE ENTRY POINTS
  28. |
  29. ---------------------------------------------------------------------------*/
  30. #include "ftk_intr.h" /* routines internal to FTK */
  31. #include "ftk_extr.h" /* routines provided or used by external FTK user */
  32. /****************************************************************************
  33. *
  34. * util_string_copy
  35. * ================
  36. *
  37. * The util_string_copy routine copies a null terminated string from source
  38. * to destination.
  39. *
  40. ****************************************************************************/
  41. #ifdef FTK_RES_FUNCTION
  42. #pragma FTK_RES_FUNCTION(util_string_copy)
  43. #endif
  44. export void
  45. util_string_copy(
  46. char * copy_to_string,
  47. char * copy_from_string
  48. )
  49. {
  50. while (*copy_from_string != '\0')
  51. {
  52. *copy_to_string++ = *copy_from_string++;
  53. }
  54. *copy_to_string = '\0';
  55. return;
  56. }
  57. /****************************************************************************
  58. *
  59. * util_mem_copy
  60. * =============
  61. *
  62. * The util_mem_copy routine copies max_copy_len bytes from the source
  63. * address to the destination address (both are virtual addresses).
  64. *
  65. ****************************************************************************/
  66. #ifdef FTK_RES_FUNCTION
  67. #pragma FTK_RES_FUNCTION(util_mem_copy)
  68. #endif
  69. export void
  70. util_mem_copy(
  71. BYTE * copy_to_mem,
  72. BYTE * copy_from_mem,
  73. UINT max_copy_len
  74. )
  75. {
  76. while (max_copy_len > 0)
  77. {
  78. *copy_to_mem = *copy_from_mem;
  79. copy_to_mem++;
  80. copy_from_mem++;
  81. max_copy_len--;
  82. }
  83. }
  84. /****************************************************************************
  85. *
  86. * util_string_concatenate
  87. * =======================
  88. *
  89. * The util_string_concatenate routine adds one null terminated string onto
  90. * the end of another, creating a new null terminated string.
  91. *
  92. ****************************************************************************/
  93. #ifdef FTK_RES_FUNCTION
  94. #pragma FTK_RES_FUNCTION(util_string_concatenate)
  95. #endif
  96. export void
  97. util_string_concatenate(
  98. char * add_to_string,
  99. char * string_to_add
  100. )
  101. {
  102. while (*add_to_string != '\0')
  103. {
  104. add_to_string++;
  105. }
  106. while (*string_to_add != '\0')
  107. {
  108. *add_to_string++ = *string_to_add++;
  109. }
  110. *add_to_string = '\0';
  111. return;
  112. }
  113. /****************************************************************************
  114. *
  115. * util_minimum
  116. * ============
  117. *
  118. * The util_minimum routine returns the minimum of three values that are
  119. * passed to it.
  120. *
  121. ****************************************************************************/
  122. #ifdef FTK_RES_FUNCTION
  123. #pragma FTK_RES_FUNCTION(util_minimum)
  124. #endif
  125. export UINT
  126. util_minimum(
  127. UINT val_1,
  128. UINT val_2,
  129. UINT val_3
  130. )
  131. {
  132. if (val_1 > val_2)
  133. {
  134. if (val_2 > val_3)
  135. {
  136. return val_3;
  137. }
  138. else
  139. {
  140. return val_2;
  141. }
  142. }
  143. else
  144. {
  145. if (val_1 > val_3)
  146. {
  147. return val_3;
  148. }
  149. else
  150. {
  151. return val_1;
  152. }
  153. }
  154. }
  155. /****************************************************************************
  156. *
  157. * util_zero_memory
  158. * ================
  159. *
  160. * The util_zero_memory routine clears an area of memory of a given size in
  161. * bytes.
  162. *
  163. ****************************************************************************/
  164. #ifdef FTK_RES_FUNCTION
  165. #pragma FTK_RES_FUNCTION(util_zero_memory)
  166. #endif
  167. export void
  168. util_zero_memory(
  169. BYTE * memory,
  170. UINT size_in_bytes
  171. )
  172. {
  173. while (size_in_bytes--)
  174. {
  175. *memory++ = 0;
  176. }
  177. return;
  178. }
  179. /****************************************************************************
  180. *
  181. * util_byte_swap_structure
  182. * ========================
  183. *
  184. * The util_byte_swap_structure routine swaps adjacent bytes in a structure
  185. * so that it can be correctly downloaded onto an adapter card. It is used
  186. * for byte swapping a node address, a multicast address and a product id
  187. * string.
  188. *
  189. ****************************************************************************/
  190. #ifdef FTK_RES_FUNCTION
  191. #pragma FTK_RES_FUNCTION(util_byte_swap_structure)
  192. #endif
  193. export void
  194. util_byte_swap_structure(
  195. BYTE * byte_based_structure,
  196. UINT size_of_structure
  197. )
  198. {
  199. UINT i;
  200. BYTE temp;
  201. for ( i = 0; i < size_of_structure; i = i+2)
  202. {
  203. temp = *byte_based_structure;
  204. *byte_based_structure = *(byte_based_structure + 1);
  205. *(byte_based_structure + 1) = temp;
  206. byte_based_structure += 2;
  207. }
  208. return;
  209. }
  210. /******** End of UTIL.C ****************************************************/