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.

234 lines
5.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: uastrfnc.cpp
  7. //
  8. // Contents: Unaligned UNICODE lstr functions for MIPS, PPC, ALPHA
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 1-11-95 davepl Created
  15. //
  16. //--------------------------------------------------------------------------
  17. // NOTE (DavePl) None of these pay any heed to locale!
  18. #include "priv.h"
  19. #pragma hdrstop
  20. #ifdef ALIGNMENT_MACHINE
  21. #ifdef UNIX
  22. #define _alloca alloca
  23. #endif /* UNIX */
  24. //+-------------------------------------------------------------------------
  25. //
  26. // Function: ualstrcpynW
  27. //
  28. // Synopsis: UNALIGNED UNICODE version of lstrcpyn
  29. //
  30. // Arguments: [lpString1] -- dest string
  31. // [lpString2] -- source string
  32. // [iMaxLength] -- max chars to copy
  33. //
  34. // Returns:
  35. //
  36. // History: 1-11-95 davepl NT Port
  37. //
  38. // Notes:
  39. //
  40. //--------------------------------------------------------------------------
  41. UNALIGNED WCHAR * ualstrcpynW(UNALIGNED WCHAR * lpString1,
  42. UNALIGNED const WCHAR * lpString2,
  43. int iMaxLength)
  44. {
  45. UNALIGNED WCHAR * src;
  46. UNALIGNED WCHAR * dst;
  47. src = (UNALIGNED WCHAR *)lpString2;
  48. dst = lpString1;
  49. while(iMaxLength && *src)
  50. {
  51. *dst++ = *src++;
  52. iMaxLength--;
  53. }
  54. if ( iMaxLength )
  55. {
  56. *dst = '\0';
  57. }
  58. else
  59. {
  60. dst--;
  61. *dst = '\0';
  62. }
  63. return dst;
  64. }
  65. //+-------------------------------------------------------------------------
  66. //
  67. // Function: ualstrcmpiW
  68. //
  69. // Synopsis: UNALIGNED UNICODE wrap of lstrcmpi
  70. //
  71. // Arguments: [dst] -- first string
  72. // [src] -- string to comapre to
  73. //
  74. // Returns:
  75. //
  76. // History: 1-11-95 davepl Created
  77. // 4-20-98 scotthan localized, bug 141655
  78. //
  79. //--------------------------------------------------------------------------
  80. int ualstrcmpiW (UNALIGNED const WCHAR * dst, UNALIGNED const WCHAR * src)
  81. {
  82. WCHAR *pwszDst, *pwszSrc;
  83. int cb ;
  84. // Make aligned copies on the stack if appropriate...
  85. // PERF - not the most inefficient tact (scotthan)
  86. // note: _alloca should always succeed, unless out of stack
  87. if( IS_ALIGNED( dst ) )
  88. pwszDst = (WCHAR*)dst ;
  89. else
  90. {
  91. cb = (ualstrlenW( dst ) + 1) * sizeof(WCHAR) ;
  92. pwszDst = (WCHAR*)_alloca( cb ) ;
  93. if (pwszDst)
  94. {
  95. CopyMemory( pwszDst, dst, cb ) ;
  96. }
  97. }
  98. if( IS_ALIGNED( src ) )
  99. pwszSrc = (WCHAR*)src ;
  100. else
  101. {
  102. cb = (ualstrlenW( src ) + 1) * sizeof(WCHAR) ;
  103. pwszSrc = (WCHAR*)_alloca( cb ) ;
  104. if (pwszSrc)
  105. {
  106. CopyMemory( pwszSrc, src, cb ) ;
  107. }
  108. }
  109. // Call the aligned method.
  110. // Note: if this ever runs on Win95, we should call StrCmpIW instead.
  111. return lstrcmpiW( pwszDst, pwszSrc ) ;
  112. }
  113. //+-------------------------------------------------------------------------
  114. //
  115. // Function: ualstrcmpW
  116. //
  117. // Synopsis: UNALIGNED UNICODE wrap of lstrcmp
  118. //
  119. // Arguments: [dst] -- first string
  120. // [src] -- string to comapre to
  121. //
  122. // Returns:
  123. //
  124. // History: 1-11-95 davepl Created
  125. // 4-29-98 scotthan localized, bug 164091
  126. //
  127. //--------------------------------------------------------------------------
  128. int ualstrcmpW (UNALIGNED const WCHAR * src, UNALIGNED const WCHAR * dst)
  129. {
  130. WCHAR *pwszDst, *pwszSrc;
  131. int cb ;
  132. // Make aligned copies on the stack if appropriate...
  133. // PERF - not the most inefficient tact (scotthan)
  134. // note: _alloca should always succeed, unless out of stack
  135. if( IS_ALIGNED( dst ) )
  136. pwszDst = (WCHAR*)dst ;
  137. else
  138. {
  139. cb = (ualstrlenW( dst ) + 1) * sizeof(WCHAR) ;
  140. pwszDst = (WCHAR*)_alloca( cb ) ;
  141. if (pwszDst)
  142. {
  143. CopyMemory( pwszDst, dst, cb ) ;
  144. }
  145. }
  146. if( IS_ALIGNED( src ) )
  147. pwszSrc = (WCHAR*)src ;
  148. else
  149. {
  150. cb = (ualstrlenW( src ) + 1) * sizeof(WCHAR) ;
  151. pwszSrc = (WCHAR*)_alloca( cb ) ;
  152. if (pwszSrc)
  153. {
  154. CopyMemory( pwszSrc, src, cb ) ;
  155. }
  156. }
  157. // Call the aligned method.
  158. // Note: if this ever runs on Win95, we should call StrCmpW instead.
  159. return lstrcmpW( pwszDst, pwszSrc ) ;
  160. }
  161. //+-------------------------------------------------------------------------
  162. //
  163. // Function: ualstrlenW
  164. //
  165. // Synopsis: UNALIGNED UNICODE version of lstrlen
  166. //
  167. // Arguments: [wcs] -- string to return length of
  168. //
  169. // Returns:
  170. //
  171. // History: 1-11-95 davepl NT Port
  172. //
  173. // Notes:
  174. //
  175. //--------------------------------------------------------------------------
  176. size_t ualstrlenW (UNALIGNED const WCHAR * wcs)
  177. {
  178. UNALIGNED const WCHAR *eos = wcs;
  179. while( *eos++ )
  180. {
  181. NULL;
  182. }
  183. return( (size_t) (eos - wcs - 1) );
  184. }
  185. //+-------------------------------------------------------------------------
  186. //
  187. // Function: ualstrcpyW
  188. //
  189. // Synopsis: UNALIGNED UNICODE version of lstrcpy
  190. //
  191. // Arguments: [dst] -- string to copy to
  192. // [src] -- string to copy from
  193. //
  194. // Returns:
  195. //
  196. // History: 1-11-95 davepl NT Port
  197. //
  198. // Notes:
  199. //
  200. //--------------------------------------------------------------------------
  201. UNALIGNED WCHAR * ualstrcpyW(UNALIGNED WCHAR * dst, UNALIGNED const WCHAR * src)
  202. {
  203. UNALIGNED WCHAR * cp = dst;
  204. while( *cp++ = *src++ )
  205. NULL ;
  206. return( dst );
  207. }
  208. #endif // ALIGNMENT_MACHINE