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.

185 lines
6.3 KiB

  1. /***
  2. *strupr.c - routine to map lower-case characters in a string to upper-case
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Converts all the lower case characters in a string to upper case,
  8. * in place.
  9. *
  10. *Revision History:
  11. * 05-31-89 JCR C version created.
  12. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  13. * copyright.
  14. * 10-02-90 GJF New-style function declarator.
  15. * 01-18-91 GJF ANSI naming.
  16. * 09-18-91 ETC Locale support under _INTL switch.
  17. * 12-08-91 ETC Updated nlsapi; added multithread.
  18. * 08-19-92 KRS Activated NLS Support.
  19. * 08-22-92 SRW Allow INTL definition to be conditional for building
  20. * ntcrt.lib
  21. * 09-02-92 SRW Get _INTL definition via ..\crt32.def
  22. * 03-10-93 CFW Remove UNDONE comment.
  23. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  24. * 06-01-93 CFW Simplify "C" locale test.
  25. * 06-02-93 SRW ignore _INTL if _NTSUBSET_ defined.
  26. * 09-15-93 CFW Use ANSI conformant "__" names.
  27. * 09-16-93 GJF Merged NT SDK and Cuda versions.
  28. * 09-22-93 CFW Use __crtxxx internal NLS API wrapper.
  29. * 10-07-93 CFW Fix macro name.
  30. * 11-09-93 CFW Add code page for __crtxxx().
  31. * 09-06-94 CFW Remove _INTL switch.
  32. * 10-24-94 GJF Sped up C locale, multi-thread case.
  33. * 12-29-94 CFW Merge non-Win32.
  34. * 01-10-95 CFW Debug CRT allocs.
  35. * 09-26-95 GJF New locking macro, and scheme, for functions which
  36. * reference the locale.
  37. * 03-17-97 RDK Added error flag to __crtLCMapStringA.
  38. * 08-12-98 GJF Revised multithread support based on threadlocinfo
  39. * struct. Also, use _alloca instead of _malloc_crt.
  40. * 05-17-99 PML Remove all Macintosh support.
  41. * 12-10-99 GB Added support for recovery from stack overflow around
  42. * _alloca().
  43. * 05-01-00 BWT Fix Posix.
  44. * 03-13-01 PML Pass per-thread cp to __crtLCMapStringA (vs7#224974).
  45. *
  46. *******************************************************************************/
  47. #include <cruntime.h>
  48. #include <string.h>
  49. #include <malloc.h>
  50. #include <locale.h>
  51. #include <setlocal.h>
  52. #include <limits.h> /* for INT_MAX */
  53. #include <mtdll.h>
  54. #include <awint.h>
  55. #include <dbgint.h>
  56. /***
  57. *char *_strupr(string) - map lower-case characters in a string to upper-case
  58. *
  59. *Purpose:
  60. * _strupr() converts lower-case characters in a null-terminated string
  61. * to their upper-case equivalents. Conversion is done in place and
  62. * characters other than lower-case letters are not modified.
  63. *
  64. * In the C locale, this function modifies only 7-bit ASCII characters
  65. * in the range 0x61 through 0x7A ('a' through 'z').
  66. *
  67. * If the locale is not the 'C' locale, LCMapString() is used to do
  68. * the work. Assumes enough space in the string to hold result.
  69. *
  70. *Entry:
  71. * char *string - string to change to upper case
  72. *
  73. *Exit:
  74. * input string address
  75. *
  76. *Exceptions:
  77. * The original string is returned unchanged on any error.
  78. *
  79. *******************************************************************************/
  80. char * __cdecl _strupr (
  81. char * string
  82. )
  83. {
  84. #if !defined(_NTSUBSET_) && !defined(_POSIX_)
  85. int dstlen; /* len of dst string, with null */
  86. unsigned char *dst; /* destination string */
  87. int malloc_flag = 0;
  88. #ifdef _MT
  89. pthreadlocinfo ptloci = _getptd()->ptlocinfo;
  90. if ( ptloci != __ptlocinfo )
  91. ptloci = __updatetlocinfo();
  92. if ( ptloci->lc_handle[LC_CTYPE] == _CLOCALEHANDLE )
  93. #else
  94. if ( __lc_handle[LC_CTYPE] == _CLOCALEHANDLE )
  95. #endif
  96. {
  97. char *cp; /* traverses string for C locale conversion */
  98. for ( cp = string ; *cp ; ++cp )
  99. if ( ('a' <= *cp) && (*cp <= 'z') )
  100. *cp -= 'a' - 'A';
  101. return(string);
  102. } /* C locale */
  103. /* Inquire size of dst string */
  104. #ifdef _MT
  105. if ( 0 == (dstlen = __crtLCMapStringA( ptloci->lc_handle[LC_CTYPE],
  106. #else
  107. if ( 0 == (dstlen = __crtLCMapStringA( __lc_handle[LC_CTYPE],
  108. #endif
  109. LCMAP_UPPERCASE,
  110. string,
  111. -1,
  112. NULL,
  113. 0,
  114. #ifdef _MT
  115. ptloci->lc_codepage,
  116. #else
  117. __lc_codepage,
  118. #endif
  119. TRUE )) )
  120. return(string);
  121. /* Allocate space for dst */
  122. __try {
  123. dst = (unsigned char *)_alloca(dstlen * sizeof(unsigned char));
  124. }
  125. __except( EXCEPTION_EXECUTE_HANDLER )
  126. {
  127. _resetstkoflw();
  128. dst = NULL;
  129. }
  130. if ( dst == NULL ) {
  131. dst = (unsigned char *)_malloc_crt(dstlen * sizeof(unsigned char));
  132. malloc_flag++;
  133. }
  134. /* Map src string to dst string in alternate case */
  135. if ( (dst != NULL) &&
  136. #ifdef _MT
  137. (__crtLCMapStringA( ptloci->lc_handle[LC_CTYPE],
  138. #else
  139. (__crtLCMapStringA( __lc_handle[LC_CTYPE],
  140. #endif
  141. LCMAP_UPPERCASE,
  142. string,
  143. -1,
  144. dst,
  145. dstlen,
  146. #ifdef _MT
  147. ptloci->lc_codepage,
  148. #else
  149. __lc_codepage,
  150. #endif
  151. TRUE ) != 0) )
  152. /* copy dst string to return string */
  153. strcpy(string, dst);
  154. if ( malloc_flag )
  155. _free_crt(dst);
  156. return(string);
  157. #else
  158. char * cp;
  159. for (cp=string; *cp; ++cp)
  160. {
  161. if ('a' <= *cp && *cp <= 'z')
  162. *cp += 'A' - 'a';
  163. }
  164. return(string);
  165. #endif
  166. }