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.

128 lines
3.8 KiB

  1. /***
  2. *stricmp.c - contains case-insensitive string comp routine _stricmp/_strcmpi
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * contains _stricmp(), also known as _strcmpi()
  8. *
  9. *Revision History:
  10. * 05-31-89 JCR C version created.
  11. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  12. * copyright.
  13. * 07-25-90 SBM Added #include <ctype.h>
  14. * 10-02-90 GJF New-style function declarator.
  15. * 01-18-91 GJF ANSI naming.
  16. * 10-11-91 GJF Bug fix! Comparison of final bytes must use unsigned
  17. * chars.
  18. * 11-08-91 GJF Fixed compiler warning.
  19. * 09-02-93 GJF Replaced _CALLTYPE1 with __cdecl.
  20. * 09-21-93 CFW Avoid cast bug.
  21. * 10-18-94 GJF Sped up C locale. Also, made multi-thread safe.
  22. * 12-29-94 CFW Merge non-Win32.
  23. * 09-26-95 GJF New locking macro, and scheme, for functions which
  24. * reference the locale.
  25. * 11-15-95 BWT Fix _NTSUBSET_
  26. * 08-10-98 GJF Revised multithread support based on threadlocinfo
  27. * struct.
  28. * 08-26-98 GJF Split out ASCII-only version.
  29. * 09-17-98 GJF Silly errors in __ascii_stricmp (found by DEC folks)
  30. * 05-17-99 PML Remove all Macintosh support.
  31. * 01-26-00 GB Modified stricmp for performance.
  32. * 03-09-00 GB Moved the performance code to toupper and tolower.
  33. * restored the original file.
  34. * 08-22-00 GB Self included this file so as that stricmp and strcmpi
  35. * have same code.
  36. *
  37. *
  38. *******************************************************************************/
  39. #include <cruntime.h>
  40. #include <string.h>
  41. #include <mtdll.h>
  42. #include <setlocal.h>
  43. #include <ctype.h>
  44. #include <locale.h>
  45. /***
  46. *int _strcmpi(dst, src), _strcmpi(dst, src) - compare strings, ignore case
  47. *
  48. *Purpose:
  49. * _stricmp/_strcmpi perform a case-insensitive string comparision.
  50. * For differences, upper case letters are mapped to lower case.
  51. * Thus, "abc_" < "ABCD" since "_" < "d".
  52. *
  53. *Entry:
  54. * char *dst, *src - strings to compare
  55. *
  56. *Return:
  57. * <0 if dst < src
  58. * 0 if dst = src
  59. * >0 if dst > src
  60. *
  61. *Exceptions:
  62. *
  63. *******************************************************************************/
  64. int __cdecl _stricmp (
  65. const char * dst,
  66. const char * src
  67. )
  68. {
  69. #if !defined(_NTSUBSET_)
  70. int f,l;
  71. #ifdef _MT
  72. pthreadlocinfo ptloci = _getptd()->ptlocinfo;
  73. if ( ptloci != __ptlocinfo )
  74. ptloci = __updatetlocinfo();
  75. if ( ptloci->lc_handle[LC_CTYPE] == _CLOCALEHANDLE ) {
  76. #else
  77. if ( __lc_handle[LC_CTYPE] == _CLOCALEHANDLE ) {
  78. #endif
  79. #endif /* !_NTSUBSET_ */
  80. return __ascii_stricmp(dst, src);
  81. #if !defined(_NTSUBSET_)
  82. }
  83. else {
  84. do {
  85. #ifdef _MT
  86. f = __tolower_mt( ptloci, (unsigned char)(*(dst++)) );
  87. l = __tolower_mt( ptloci, (unsigned char)(*(src++)) );
  88. #else
  89. f = tolower( (unsigned char)(*(dst++)) );
  90. l = tolower( (unsigned char)(*(src++)) );
  91. #endif
  92. } while ( f && (f == l) );
  93. }
  94. return(f - l);
  95. #endif /* !_NTSUBSET_ */
  96. }
  97. #ifndef _M_IX86
  98. int __cdecl __ascii_stricmp (
  99. const char * dst,
  100. const char * src
  101. )
  102. {
  103. int f, l;
  104. do {
  105. if ( ((f = (unsigned char)(*(dst++))) >= 'A') &&
  106. (f <= 'Z') )
  107. f -= 'A' - 'a';
  108. if ( ((l = (unsigned char)(*(src++))) >= 'A') &&
  109. (l <= 'Z') )
  110. l -= 'A' - 'a';
  111. } while ( f && (f == l) );
  112. return(f - l);
  113. }
  114. #endif