Source code of Windows XP (NT5)
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.

222 lines
5.3 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. CopyMemory( pwszDst, dst, cb ) ;
  94. }
  95. if( IS_ALIGNED( src ) )
  96. pwszSrc = (WCHAR*)src ;
  97. else
  98. {
  99. cb = (ualstrlenW( src ) + 1) * sizeof(WCHAR) ;
  100. pwszSrc = (WCHAR*)_alloca( cb ) ;
  101. CopyMemory( pwszSrc, src, cb ) ;
  102. }
  103. // Call the aligned method.
  104. // Note: if this ever runs on Win95, we should call StrCmpIW instead.
  105. return lstrcmpiW( pwszDst, pwszSrc ) ;
  106. }
  107. //+-------------------------------------------------------------------------
  108. //
  109. // Function: ualstrcmpW
  110. //
  111. // Synopsis: UNALIGNED UNICODE wrap of lstrcmp
  112. //
  113. // Arguments: [dst] -- first string
  114. // [src] -- string to comapre to
  115. //
  116. // Returns:
  117. //
  118. // History: 1-11-95 davepl Created
  119. // 4-29-98 scotthan localized, bug 164091
  120. //
  121. //--------------------------------------------------------------------------
  122. int ualstrcmpW (UNALIGNED const WCHAR * src, UNALIGNED const WCHAR * dst)
  123. {
  124. WCHAR *pwszDst, *pwszSrc;
  125. int cb ;
  126. // Make aligned copies on the stack if appropriate...
  127. // PERF - not the most inefficient tact (scotthan)
  128. // note: _alloca should always succeed, unless out of stack
  129. if( IS_ALIGNED( dst ) )
  130. pwszDst = (WCHAR*)dst ;
  131. else
  132. {
  133. cb = (ualstrlenW( dst ) + 1) * sizeof(WCHAR) ;
  134. pwszDst = (WCHAR*)_alloca( cb ) ;
  135. CopyMemory( pwszDst, dst, cb ) ;
  136. }
  137. if( IS_ALIGNED( src ) )
  138. pwszSrc = (WCHAR*)src ;
  139. else
  140. {
  141. cb = (ualstrlenW( src ) + 1) * sizeof(WCHAR) ;
  142. pwszSrc = (WCHAR*)_alloca( cb ) ;
  143. CopyMemory( pwszSrc, src, cb ) ;
  144. }
  145. // Call the aligned method.
  146. // Note: if this ever runs on Win95, we should call StrCmpW instead.
  147. return lstrcmpW( pwszDst, pwszSrc ) ;
  148. }
  149. //+-------------------------------------------------------------------------
  150. //
  151. // Function: ualstrlenW
  152. //
  153. // Synopsis: UNALIGNED UNICODE version of lstrlen
  154. //
  155. // Arguments: [wcs] -- string to return length of
  156. //
  157. // Returns:
  158. //
  159. // History: 1-11-95 davepl NT Port
  160. //
  161. // Notes:
  162. //
  163. //--------------------------------------------------------------------------
  164. size_t ualstrlenW (UNALIGNED const WCHAR * wcs)
  165. {
  166. UNALIGNED const WCHAR *eos = wcs;
  167. while( *eos++ )
  168. {
  169. NULL;
  170. }
  171. return( (size_t) (eos - wcs - 1) );
  172. }
  173. //+-------------------------------------------------------------------------
  174. //
  175. // Function: ualstrcpyW
  176. //
  177. // Synopsis: UNALIGNED UNICODE version of lstrcpy
  178. //
  179. // Arguments: [dst] -- string to copy to
  180. // [src] -- string to copy from
  181. //
  182. // Returns:
  183. //
  184. // History: 1-11-95 davepl NT Port
  185. //
  186. // Notes:
  187. //
  188. //--------------------------------------------------------------------------
  189. UNALIGNED WCHAR * ualstrcpyW(UNALIGNED WCHAR * dst, UNALIGNED const WCHAR * src)
  190. {
  191. UNALIGNED WCHAR * cp = dst;
  192. while( *cp++ = *src++ )
  193. NULL ;
  194. return( dst );
  195. }
  196. #endif // ALIGNMENT_MACHINE