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.

122 lines
2.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997.
  5. //
  6. // File: util.hxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // Coupling:
  15. //
  16. // Notes:
  17. //
  18. // History: 9-11-1996 benl Created
  19. //
  20. //----------------------------------------------------------------------------
  21. #ifndef _CUTIL
  22. #define _CUTIL
  23. void PrintGuid(FILE * file, const GUID & guid);
  24. void MySRand(DWORD & dwBase);
  25. INT MyRand(INT);
  26. SHORT MyRand16(SHORT);
  27. LONGLONG MyRand64(LONGLONG llLimit);
  28. void SwapBuffers(INT cbBuf1, BYTE * pBuffer1, INT cbBuf2, BYTE * pBuffer2);
  29. void DumpRawBytes(BYTE * pBytes, UINT cBytes);
  30. void DumpRawDwords(DWORD * pDwords, UINT cBytes);
  31. void HexStrToInt64(LPCTSTR szIn, __int64 & i64Out);
  32. //+---------------------------------------------------------------------------
  33. //
  34. // Function: Swap
  35. //
  36. // Synopsis: Generic template swap routine
  37. //
  38. // Arguments: [t1] -- item to swap
  39. // [t2] -- item to swap
  40. //
  41. // Returns:
  42. //
  43. // History: 9-30-1997 benl Created
  44. //
  45. // Notes: type T has to have an assignment operator
  46. //
  47. //----------------------------------------------------------------------------
  48. template <class T> void Swap(T & t1, T & t2)
  49. {
  50. T t3;
  51. t3 = t1;
  52. t1 = t2;
  53. t2 = t3;
  54. } // Swap
  55. //+---------------------------------------------------------------------------
  56. //
  57. // Function: ALIGN
  58. //
  59. // Synopsis: simple inline to do alignment
  60. //
  61. // Arguments: [dwNumber] --
  62. // [dwAlignment] --
  63. //
  64. // Returns:
  65. //
  66. // History: 12-18-1997 benl Created
  67. //
  68. // Notes:
  69. //
  70. //----------------------------------------------------------------------------
  71. inline ULONG ALIGN(ULONG dwNumber, ULONG dwAlignment)
  72. {
  73. return ((dwNumber + dwAlignment - 1) / dwAlignment) * dwAlignment;
  74. } // ALIGN
  75. //+---------------------------------------------------------------------------
  76. //
  77. // Function: ALIGN64
  78. //
  79. // Synopsis: simple inline to do alignment for 64bit ints
  80. //
  81. // Arguments: [dwNumber] --
  82. // [dwAlignment] --
  83. //
  84. // Returns:
  85. //
  86. // History: 12-18-1997 benl Created
  87. //
  88. // Notes:
  89. //
  90. //----------------------------------------------------------------------------
  91. inline LONGLONG ALIGN64(LONGLONG llNumber, LONGLONG llAlignment)
  92. {
  93. return ((llNumber + llAlignment - 1) / llAlignment) * llAlignment;
  94. } // ALIGN
  95. #if defined(UNICODE) || defined(_UNICODE)
  96. #define W_TO_TSTR _T("%s")
  97. #define S_TO_TSTR _T("%S")
  98. #define T_TO_STR "%S"
  99. #define T_TO_WSTR L"%s"
  100. #else
  101. #define W_TO_TSTR _T("%S")
  102. #define S_TO_TSTR _T("%s")
  103. #define T_TO_STR "%s"
  104. #define T_TO_WSTR L"%S"
  105. #endif
  106. #endif