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.

250 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. macros.h
  5. Abstract:
  6. Contains all internal macros used in INTERNET.DLL
  7. Contents:
  8. ROUND_UP_?K
  9. ROUND_UP_DWORD
  10. NEW
  11. DEL
  12. NEW_STRING
  13. DEL_STRING
  14. NEW_MEMORY
  15. ZAP
  16. PRIVATE
  17. PUBLIC
  18. GLOBAL
  19. LOCAL
  20. DEBUG_FUNCTION
  21. SKIPWS
  22. Author:
  23. Richard L Firth (rfirth) 16-Nov-1994
  24. Revision History:
  25. 16-Nov-1994 rfirth
  26. Created
  27. --*/
  28. //
  29. // macros
  30. //
  31. //
  32. // ROUND_UP_ - return (n) rounded up to the next (k) bytes
  33. //
  34. #define ROUND_UP_NK(n, k) (((n) + ((_ ## k ## K) - 1)) & -(_ ## k ## K))
  35. #define ROUND_UP_2K(n) ROUND_UP_NK(n, 2)
  36. #define ROUND_UP_4K(n) ROUND_UP_NK(n, 4)
  37. #define ROUND_UP_8K(n) ROUND_UP_NK(n, 8)
  38. #define ROUND_UP_16K(n) ROUND_UP_NK(n, 16)
  39. //
  40. // ROUND_UP_DWORD - return (n) rounded up to the next 4 bytes
  41. //
  42. #define ROUND_UP_DWORD(value) \
  43. (((value) + sizeof(DWORD) - 1) & ~(sizeof(DWORD) - 1))
  44. //
  45. // ARRAY_ELEMENTS - returns number of elements in array
  46. //
  47. #define ARRAY_ELEMENTS(array) \
  48. (sizeof(array)/sizeof(array[0]))
  49. //
  50. // NEW - allocates a new 'object' of type (obj). Memory is allocated with
  51. // LocalAlloc and initialized to zeroes
  52. //
  53. #define NEW(object) \
  54. (object FAR *)ALLOCATE_ZERO_MEMORY(sizeof(object))
  55. //
  56. // DEL - (should be DELETE, but that symbol is taken) - does opposite of NEW()
  57. //
  58. #define DEL(object) \
  59. FREE_MEMORY(object)
  60. //
  61. // NEW_STRING - performs NEW for a string
  62. //
  63. #define NEW_STRING(string) \
  64. NewString(string, 0)
  65. //
  66. // DEL_STRING - performs DEL for a string
  67. //
  68. #define DEL_STRING(string) \
  69. FREE_MEMORY(string)
  70. //
  71. // NEW_MEMORY - performs NEW for arbitrary sized memory
  72. //
  73. #define NEW_MEMORY(n, type) \
  74. (type FAR *)ALLOCATE_FIXED_MEMORY(n * sizeof(type))
  75. //
  76. // ZAP - zeroes an object (must be a variable, not a pointer)
  77. //
  78. #define ZAP(thing) \
  79. ZeroMemory((PVOID)&thing, sizeof(thing))
  80. //
  81. // STRTOUL - character-width independent (compile-time controlled) strtoul
  82. //
  83. #define STRTOUL strtoul
  84. //
  85. // PRIVATE - make static items visible in debug version *FOR GLOBALS ONLY*. Use
  86. // LOCAL in functions
  87. //
  88. #if INET_DEBUG
  89. #define PRIVATE
  90. #else
  91. //#define PRIVATE static
  92. #define PRIVATE
  93. #endif // INET_DEBUG
  94. //
  95. // PUBLIC - just used as an aide-a-programmer pour le nonce
  96. //
  97. #define PUBLIC
  98. //
  99. // GLOBAL - same as PUBLIC, aide-a-programmer (for now) that tells you this
  100. // thang has global scope
  101. //
  102. #define GLOBAL
  103. //
  104. // LOCAL - always expands to static, so you know that this thing only has
  105. // local scope (within the current block)
  106. //
  107. #define LOCAL static
  108. //
  109. // DEBUG_FUNCTION - this is a debug-only routine (if it get compiled in retail
  110. // version a compile-time error is generated)
  111. //
  112. #if INET_DEBUG
  113. #define DEBUG_FUNCTION
  114. #else
  115. #define DEBUG_FUNCTION
  116. #endif // INET_DEBUG
  117. //
  118. // SKIPWS - skips blank widespace on the front of a string
  119. //
  120. #define SKIPWS(s) while (*(s)==' ' || *(s)=='\t') (s)++;
  121. //
  122. // MAKE_LOWER - takes an assumed upper character and bit manipulates into a lower.
  123. // (make sure the character is Upper case alpha char to begin, otherwise it corrupts)
  124. //
  125. #define MAKE_LOWER(c) (c | 0x20)
  126. //
  127. // MAKE_UPPER - takes an assumed lower character and bit manipulates into a upper.
  128. // (make sure the character is Lower case alpha char to begin, otherwise it corrupts)
  129. //
  130. #define MAKE_UPPER(c) (c & 0xdf)
  131. //
  132. // FASTCALL - used to bypass problems that may arise with UNIX compilers
  133. //
  134. #ifdef FASTCALL
  135. #undef FASTCALL
  136. #endif
  137. #ifdef unix
  138. #define FASTCALL
  139. #else
  140. #define FASTCALL __fastcall
  141. #endif
  142. //
  143. // macro to cast FILETIME to LONGLONG
  144. //
  145. #define FT2LL(x) ( ((LONGLONG)((x).dwLowDateTime)) | (((LONGLONG)((x).dwHighDateTime))<<32) )
  146. //
  147. // Inline function to handle adding LONGLONG to FILETIME.
  148. //
  149. static __inline
  150. void AddLongLongToFT( IN OUT LPFILETIME lpft,
  151. IN LONGLONG llVal )
  152. {
  153. LONGLONG llTmp;
  154. llTmp = FT2LL(*lpft);
  155. llTmp += llVal;
  156. lpft->dwLowDateTime = ((LPDWORD)&llTmp)[0];
  157. lpft->dwHighDateTime = ((LPDWORD)&llTmp)[1];
  158. }
  159. //
  160. // Macro to compute the number of bytes between two pointers
  161. // The type of this expression is size_t, a signed integral
  162. // type matching the size of a pointer
  163. //
  164. #define PtrDifference(x,y) ((LPBYTE)(x) - (LPBYTE)(y))
  165. //
  166. // Macro to typecast 64-bit quantity to 32-bits
  167. // Asserts in debug mode if the typecast loses information
  168. //
  169. #ifdef DBG
  170. #define GuardedCast(x) ((x)<=0xFFFFFFFFL ? (DWORD)(x) : (InternetAssert(FALSE, __FILE__, __LINE__), 0))
  171. #else
  172. #define GuardedCast(x) (DWORD)(x)
  173. #endif
  174. // Macro for the most common case
  175. #define PtrDiff32(x,y) (GuardedCast(PtrDifference(x,y)))
  176. #define NOVTABLE __declspec(novtable)