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.

181 lines
5.1 KiB

  1. #include "private.h"
  2. // Thi is not working since ATL uses CRT dll. we should not use ATL to remove CRT bondage
  3. #define CPP_FUNCTIONS
  4. #include "icrtfree.h" // Code to help free modules from the bondage and tyranny of CRT libraries
  5. #ifdef NOCLIB
  6. #if defined(_M_IX86)
  7. extern "C" int _fltused = 1;
  8. /*----------------------------------------------------------------------------
  9. _ftol - convert a float value to an __int64. The argument is on the top of
  10. the stack, the result is returned in EAX (low) and EDX (high). Note that
  11. this is used for all float to integral convertion and deals with both
  12. signed and unsigned values - the compiler just ignores the EDX value. The
  13. LongFromDouble and UlongFromDouble functions check the range, so this
  14. cavlier bitwise truncation doesn't matter.
  15. ------------------------------------------------------------------- JohnBo -*/
  16. extern "C" __declspec(naked) void __cdecl _ftol(void)
  17. {
  18. // A simple FISTP is all that is required (so why is this out of line?
  19. // possible the CRT version handles overflow differently?)
  20. __asm PUSH EDX; // Just to make room on the stack
  21. __asm PUSH EAX;
  22. __asm FISTP QWORD PTR [ESP]; // Pop long off top of FP stack
  23. __asm POP EAX; // And put back into EDX/EAX - tedious eh?
  24. __asm POP EDX; // Stack grows downwards, so EDX is high.
  25. __asm RET;
  26. }
  27. #endif
  28. /*
  29. * memmove
  30. */
  31. void * __cdecl memmove(void * dst, const void * src, size_t count)
  32. {
  33. void * ret = dst;
  34. if (dst <= src || (char *)dst >= ((char *)src + count)) {
  35. /*
  36. * Non-Overlapping Buffers
  37. * copy from lower addresses to higher addresses
  38. */
  39. // memcpy is intrinsic
  40. memcpy(dst, src, count);
  41. } else {
  42. /*
  43. * Overlapping Buffers
  44. * copy from higher addresses to lower addresses
  45. */
  46. dst = (char *)dst + count - 1;
  47. src = (char *)src + count - 1;
  48. while (count--) {
  49. *(char *)dst = *(char *)src;
  50. dst = (char *)dst - 1;
  51. src = (char *)src - 1;
  52. }
  53. }
  54. return(ret);
  55. }
  56. /*---------------------------------------------------------------------------
  57. StrCopyW
  58. Unicode String copy
  59. ---------------------------------------------------------------------------*/
  60. LPWSTR ImeRtl_StrCopyW(LPWSTR pwDest, LPCWSTR pwSrc)
  61. {
  62. LPWSTR pwStart = pwDest;
  63. while (*pwDest++ = *pwSrc++)
  64. ;
  65. return (pwStart);
  66. }
  67. /*---------------------------------------------------------------------------
  68. StrnCopyW
  69. Unicode String copy
  70. ---------------------------------------------------------------------------*/
  71. LPWSTR ImeRtl_StrnCopyW(LPWSTR pwDest, LPCWSTR pwSrc, UINT uiCount)
  72. {
  73. LPWSTR pwStart = pwDest;
  74. while (uiCount && (*pwDest++ = *pwSrc++)) // copy string
  75. uiCount--;
  76. if (uiCount) // pad out with zeroes
  77. while (--uiCount)
  78. *pwDest++ = 0;
  79. return (pwStart);
  80. }
  81. /*---------------------------------------------------------------------------
  82. StrCmpW
  83. Unicode String compare
  84. ---------------------------------------------------------------------------*/
  85. INT ImeRtl_StrCmpW(LPCWSTR pwSz1, LPCWSTR pwSz2)
  86. {
  87. INT cch1 = lstrlenW(pwSz1);
  88. INT cch2 = lstrlenW(pwSz2);
  89. if (cch1 != cch2)
  90. return cch2 - cch1;
  91. for (INT i=0; i<cch1; i++)
  92. {
  93. if (pwSz1[i] != pwSz2[i])
  94. return i+1;
  95. }
  96. return 0;
  97. }
  98. /*---------------------------------------------------------------------------
  99. StrnCmpW
  100. Unicode String compare
  101. ---------------------------------------------------------------------------*/
  102. INT ImeRtl_StrnCmpW(LPCWSTR wszFirst, LPCWSTR wszLast, UINT uiCount)
  103. {
  104. if (!uiCount)
  105. return(0);
  106. while (--uiCount && *wszFirst && *wszFirst == *wszLast)
  107. {
  108. wszFirst++;
  109. wszLast++;
  110. }
  111. return (*wszFirst - *wszLast);
  112. }
  113. /*---------------------------------------------------------------------------
  114. StrnCatW
  115. Unicode String concatenation
  116. ---------------------------------------------------------------------------*/
  117. WCHAR * __cdecl Imertl_StrCatW(WCHAR *wszDest, const WCHAR *wszSource)
  118. {
  119. WCHAR *wszStart = wszDest;
  120. WCHAR *pwch;
  121. for (pwch = wszDest; *pwch; pwch++);
  122. while (*pwch++ = *wszSource++);
  123. return(wszStart);
  124. }
  125. wchar_t * __cdecl wcscpy(wchar_t *a, const wchar_t *b)
  126. {
  127. return ImeRtl_StrCopyW(a,b);
  128. }
  129. wchar_t * __cdecl wcsncpy(wchar_t *a, const wchar_t *b, size_t c)
  130. {
  131. return ImeRtl_StrnCopyW(a,b,c);
  132. }
  133. size_t __cdecl wcslen(const wchar_t *a)
  134. {
  135. return lstrlenW(a);
  136. }
  137. int __cdecl wcscmp(const wchar_t *a, const wchar_t *b)
  138. {
  139. return ImeRtl_StrCmpW(a, b);
  140. }
  141. int __cdecl wcsncmp(const wchar_t *a, const wchar_t *b, size_t c)
  142. {
  143. return ImeRtl_StrnCmpW(a, b, c);
  144. }
  145. wchar_t * __cdecl wcscat(wchar_t *pwSz1, const wchar_t *pwSz2)
  146. {
  147. return Imertl_StrCatW(pwSz1, pwSz2);
  148. }
  149. #endif