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.

304 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. alignstr.c
  5. Abstract:
  6. This module implements a number of UNICODE string routines. These
  7. routines are equivalent to the corresponding C runtime routines
  8. with the exception that they can handle unaligned parameters.
  9. Author:
  10. Forrest Foltz (forrestf) 1-Jan-2000
  11. Revision History:
  12. --*/
  13. #include "basedll.h"
  14. #if !defined(_X86_)
  15. //
  16. // These routines are not intended to be called directly from source,
  17. // rather they are worker functions designed to be called from corresponding
  18. // inlines in alignstr.h.
  19. //
  20. // alignstr.h will never reference these routines on an x86 platform.
  21. //
  22. //++
  23. //
  24. // PUWSTR
  25. // __cdecl
  26. // uaw_wcschr(
  27. // IN PCUWSTR String,
  28. // IN WCHAR Character
  29. // )
  30. //
  31. // Routine Description:
  32. //
  33. // Searches String for the first occurence of Character.
  34. //
  35. // Arguments:
  36. //
  37. // String - Supplies an unaligned pointer to the null-terminated UNICODE
  38. // string to search.
  39. //
  40. // Character - Supplies the UNICODE character to search for.
  41. //
  42. // Return Value:
  43. //
  44. // Returns an unaligned pointer to the first matching character within String
  45. // if found, or NULL if no match was located.
  46. //
  47. //--
  48. PUWSTR
  49. __cdecl
  50. uaw_wcschr(
  51. IN PCUWSTR String,
  52. IN WCHAR Character
  53. )
  54. {
  55. PUWSTR pch;
  56. //
  57. // Search the whole string looking for the first matching character.
  58. // Note that the search INCLUDES the terminating null character.
  59. //
  60. pch = (PUWSTR)String;
  61. while (TRUE) {
  62. if (*pch == Character) {
  63. return pch;
  64. }
  65. if (*pch == 0) {
  66. return NULL;
  67. }
  68. pch++;
  69. }
  70. }
  71. //++
  72. //
  73. // PUWSTR
  74. // __cdecl
  75. // uaw_wcscpy(
  76. // IN PUWSTR Destination,
  77. // IN PCUWSTR Source
  78. // )
  79. //
  80. // Routine Description:
  81. //
  82. // Copies a null-terminated UNICODE string.
  83. //
  84. // Arguments:
  85. //
  86. // Destination - Supplies a possibly unaligned pointer to the destination
  87. // of the copy.
  88. //
  89. // Source - Supplies a possibly unaligned pointer to the UNICODE string
  90. // to be copied.
  91. //
  92. // Return Value:
  93. //
  94. // Returns a possibly unaligned pointer to the destination of the copy.
  95. //
  96. //--
  97. PUWSTR
  98. _cdecl
  99. uaw_wcscpy(
  100. IN PUWSTR Destination,
  101. IN PCUWSTR Source
  102. )
  103. {
  104. PCUWSTR src;
  105. PUWSTR dst;
  106. src = Source;
  107. dst = Destination;
  108. while (TRUE) {
  109. *dst = *src;
  110. if (*src == 0) {
  111. return Destination;
  112. }
  113. dst++;
  114. src++;
  115. }
  116. }
  117. //++
  118. //
  119. // size_t
  120. // __cdecl
  121. // uaw_wcslen(
  122. // IN PCUWSTR String
  123. // )
  124. //
  125. // Routine Description:
  126. //
  127. // Determines the number of characters within a null-terminated UNICODE
  128. // string, excluding the null-terminator.
  129. //
  130. // Arguments:
  131. //
  132. // String - Supplies an unaligned pointer to the null-terminated UNICODE
  133. // string.
  134. //
  135. // Return Value:
  136. //
  137. // Returns the number of characters within String.
  138. //
  139. //--
  140. size_t
  141. __cdecl
  142. uaw_wcslen(
  143. IN PCUWSTR String
  144. )
  145. {
  146. PCUWSTR pch;
  147. pch = String;
  148. while (*pch != 0) {
  149. pch++;
  150. }
  151. return pch - String;
  152. }
  153. //++
  154. //
  155. // PUWSTR
  156. // __cdecl
  157. // uaw_wcsrchr(
  158. // IN PCUWSTR String,
  159. // IN WCHAR Character
  160. // )
  161. //
  162. // Routine Description:
  163. //
  164. // Searches String for the last occurence of Character.
  165. //
  166. // Arguments:
  167. //
  168. // String - Supplies an unaligned pointer to the null-terminated UNICODE
  169. // string to search.
  170. //
  171. // Character - Supplies the UNICODE character to search for.
  172. //
  173. // Return Value:
  174. //
  175. // Returns an unaligned pointer to the last matching character within String
  176. // if found, or NULL if no match was located.
  177. //
  178. //--
  179. PUWSTR
  180. __cdecl
  181. uaw_wcsrchr(
  182. IN PCUWSTR String,
  183. IN WCHAR Character
  184. )
  185. {
  186. PCUWSTR pch;
  187. PUWSTR lastMatch;
  188. lastMatch = NULL;
  189. pch = String;
  190. //
  191. // Search the whole string looking for the last matching character.
  192. // Note that the search INCLUDES the terminating null character.
  193. //
  194. while (TRUE) {
  195. if (*pch == Character) {
  196. //
  197. // Found either the first match or a new match closer to the end,
  198. // record its position.
  199. //
  200. lastMatch = (PUWSTR)pch;
  201. }
  202. if (*pch == 0) {
  203. return lastMatch;
  204. }
  205. pch++;
  206. }
  207. }
  208. int
  209. APIENTRY
  210. uaw_lstrcmpW(
  211. PCUWSTR String1,
  212. PCUWSTR String2
  213. )
  214. {
  215. PCWSTR alignedString1;
  216. PCWSTR alignedString2;
  217. //
  218. // Create aligned copies of these strings and pass to the real
  219. // function.
  220. //
  221. WSTR_ALIGNED_STACK_COPY( &alignedString1, String1 );
  222. WSTR_ALIGNED_STACK_COPY( &alignedString2, String2 );
  223. return lstrcmpW( alignedString1, alignedString2 );
  224. }
  225. int
  226. APIENTRY
  227. uaw_lstrcmpiW(
  228. PCUWSTR String1,
  229. PCUWSTR String2
  230. )
  231. {
  232. PCWSTR alignedString1;
  233. PCWSTR alignedString2;
  234. //
  235. // Create aligned copies of these strings and pass to the real
  236. // function.
  237. //
  238. WSTR_ALIGNED_STACK_COPY( &alignedString1, String1 );
  239. WSTR_ALIGNED_STACK_COPY( &alignedString2, String2 );
  240. return lstrcmpiW( alignedString1, alignedString2 );
  241. }
  242. int
  243. APIENTRY
  244. uaw_lstrlenW(
  245. LPCUWSTR lpString
  246. )
  247. {
  248. if (!lpString)
  249. return 0;
  250. __try {
  251. return uaw_wcslen(lpString);
  252. }
  253. __except (EXCEPTION_EXECUTE_HANDLER) {
  254. return 0;
  255. }
  256. }
  257. #endif // _X86_