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.

164 lines
5.5 KiB

  1. /***
  2. *wcsupr.c - routine to map lower-case characters in a wchar_t string
  3. * to upper-case
  4. *
  5. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  6. *
  7. *Purpose:
  8. * Converts all the lower case characters in a wchar_t string
  9. * to upper case, in place.
  10. *
  11. *Revision History:
  12. * 09-09-91 ETC Created from strupr.c and wcslwr.c
  13. * 04-06-92 KRS Make work without _INTL also.
  14. * 08-19-92 KRS Activate NLS support.
  15. * 08-22-92 SRW Allow INTL definition to be conditional for building ntcrt.lib
  16. * 09-02-92 SRW Get _INTL definition via ..\crt32.def
  17. * 02-16-93 CFW Optimize test for lowercase in "C" locale.
  18. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  19. * 06-02-93 SRW ignore _INTL if _NTSUBSET_ defined.
  20. * 09-15-93 CFW Use ANSI conformant "__" names.
  21. * 09-16-93 GJF Merged NT SDK and Cuda versions.
  22. * 09-22-93 CFW Use __crtxxx internal NLS API wrapper.
  23. * 11-09-93 CFW Add code page for __crtxxx().
  24. * 02-07-94 CFW POSIXify.
  25. * 09-06-94 CFW Remove _INTL switch.
  26. * 10-25-94 GJF Sped up C locale, multi-thread case.
  27. * 01-10-95 CFW Debug CRT allocs.
  28. * 09-26-95 GJF New locking macro, and scheme, for functions which
  29. * reference the locale.
  30. * 08-17-98 GJF Revised multithread support based on threadlocinfo
  31. * struct. Also, use _alloca instead of _malloc_crt if
  32. * possible.
  33. * 10-19-98 GJF Major typo, = should have been ==
  34. * 12-10-99 GB Added support for recovery from stack overflow around
  35. * _alloca().
  36. * 08-08-02 BWT Don't use alloca - just use local buf for short strings,
  37. * and heap for long ones.
  38. *
  39. *******************************************************************************/
  40. #ifndef _POSIX_
  41. #include <cruntime.h>
  42. #include <string.h>
  43. #include <malloc.h>
  44. #include <locale.h>
  45. #include <ctype.h>
  46. #include <setlocal.h>
  47. #include <mtdll.h>
  48. #include <awint.h>
  49. #include <dbgint.h>
  50. /***
  51. *wchar_t *_wcsupr(string) - map lower-case characters in a string to upper-case
  52. *
  53. *Purpose:
  54. * wcsupr converts lower-case characters in a null-terminated wchar_t
  55. * string to their upper-case equivalents. The result may be longer or
  56. * shorter than the original string. Assumes enough space in string
  57. * to hold the result.
  58. *
  59. *Entry:
  60. * wchar_t *wsrc - wchar_t string to change to upper case
  61. *
  62. *Exit:
  63. * input string address
  64. *
  65. *Exceptions:
  66. * on an error, the original string is unaltered
  67. *
  68. *******************************************************************************/
  69. wchar_t * __cdecl _wcsupr (
  70. wchar_t * wsrc
  71. )
  72. {
  73. #ifndef _NTSUBSET_
  74. wchar_t *p; /* traverses string for C locale conversion */
  75. wchar_t *wdst; /* wide version of string in alternate case */
  76. wchar_t wslocal[128]; /* Local buffer to use for conversion of short strings */
  77. int dstlen; /* len of wdst string, wide chars, with null */
  78. int malloc_flag = 0;
  79. #ifdef _MT
  80. pthreadlocinfo ptloci = _getptd()->ptlocinfo;
  81. if ( ptloci != __ptlocinfo )
  82. ptloci = __updatetlocinfo();
  83. if ( ptloci->lc_handle[LC_CTYPE] == _CLOCALEHANDLE ) {
  84. #else
  85. if ( __lc_handle[LC_CTYPE] == _CLOCALEHANDLE ) {
  86. #endif
  87. for ( p = wsrc ; *p ; p++ )
  88. {
  89. if ( (*p >= (wchar_t)L'a') && (*p <= (wchar_t)L'z') )
  90. *p = *p - (L'a' - L'A');
  91. }
  92. return(wsrc);
  93. } /* C locale */
  94. /* Inquire size of wdst string */
  95. #ifdef _MT
  96. if ( (dstlen = __crtLCMapStringW( ptloci->lc_handle[LC_CTYPE],
  97. #else
  98. if ( (dstlen = __crtLCMapStringW( __lc_handle[LC_CTYPE],
  99. #endif
  100. LCMAP_UPPERCASE,
  101. wsrc,
  102. -1,
  103. NULL,
  104. 0,
  105. #ifdef _MT
  106. ptloci->lc_codepage )) == 0 )
  107. #else
  108. __lc_codepage )) == 0 )
  109. #endif
  110. return(wsrc);
  111. if (dstlen*sizeof(wchar_t) < sizeof(wslocal)) {
  112. wdst = wslocal;
  113. } else {
  114. wdst = (wchar_t *)_malloc_crt(dstlen * sizeof(wchar_t));
  115. malloc_flag++;
  116. }
  117. /* Map wrc string to wide-character wdst string in alternate case */
  118. if ( (wdst != NULL) &&
  119. #ifdef _MT
  120. (__crtLCMapStringW( ptloci->lc_handle[LC_CTYPE],
  121. #else
  122. (__crtLCMapStringW( __lc_handle[LC_CTYPE],
  123. #endif
  124. LCMAP_UPPERCASE,
  125. wsrc,
  126. -1,
  127. wdst,
  128. dstlen,
  129. #ifdef _MT
  130. ptloci->lc_codepage ) != 0) )
  131. #else
  132. __lc_codepage ) != 0) )
  133. #endif
  134. /* Copy wdst string to user string */
  135. wcscpy (wsrc, wdst);
  136. if ( malloc_flag )
  137. _free_crt(wdst);
  138. #else /* NTSUBSET */
  139. wchar_t * p;
  140. for (p=wsrc; *p; ++p)
  141. {
  142. if (L'a' <= *p && *p <= L'z')
  143. *p += (wchar_t)(L'A' - L'a');
  144. }
  145. #endif
  146. return(wsrc);
  147. }
  148. #endif /* _POSIX_ */