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.

101 lines
2.6 KiB

  1. /***
  2. * mbsstr.c - Search for one MBCS string inside another
  3. *
  4. * Copyright (c) 1988-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Search for one MBCS string inside another
  8. *
  9. *Revision History:
  10. * 11-19-92 KRS Ported from 16-bit sources.
  11. * 10-06-93 GJF Replaced _CRTAPI1 with __cdecl.
  12. * 05-09-94 CFW Optimize for SBCS.
  13. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  14. * 04-20-98 GJF Implemented multithread support based on threadmbcinfo
  15. * structs
  16. *
  17. *******************************************************************************/
  18. #ifdef _MBCS
  19. #include <cruntime.h>
  20. #include <mbdata.h>
  21. #include <mbctype.h>
  22. #include <mbstring.h>
  23. #include <mtdll.h>
  24. #include <stddef.h>
  25. #include <string.h>
  26. /***
  27. * _mbsstr - Search for one MBCS string inside another
  28. *
  29. *Purpose:
  30. * Find the first occurrence of str2 in str1.
  31. *
  32. *Entry:
  33. * unsigned char *str1 = beginning of string
  34. * unsigned char *str2 = string to search for
  35. *
  36. *Exit:
  37. * Returns a pointer to the first occurrence of str2 in
  38. * str1, or NULL if str2 does not occur in str1
  39. *
  40. *Exceptions:
  41. *
  42. *******************************************************************************/
  43. unsigned char * __cdecl _mbsstr(
  44. const unsigned char *str1,
  45. const unsigned char *str2
  46. )
  47. {
  48. unsigned char *cp, *s1, *s2, *endp;
  49. #ifdef _MT
  50. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  51. if ( ptmbci != __ptmbcinfo )
  52. ptmbci = __updatetmbcinfo();
  53. if ( _ISNOTMBCP_MT(ptmbci) )
  54. #else
  55. if ( _ISNOTMBCP )
  56. #endif
  57. return strstr(str1, str2);
  58. if ( *str2 == '\0')
  59. return (unsigned char *)str1;
  60. cp = (unsigned char *) str1;
  61. endp = (unsigned char *) (str1 + (strlen(str1) - strlen(str2)));
  62. while (*cp && (cp <= endp))
  63. {
  64. s1 = cp;
  65. s2 = (char *) str2;
  66. /*
  67. * MBCS: ok to ++ since doing equality comparison.
  68. * [This depends on MBCS strings being "legal".]
  69. */
  70. while ( *s1 && *s2 && (*s1 == *s2) )
  71. s1++, s2++;
  72. if (!(*s2))
  73. return(cp); /* success! */
  74. /*
  75. * bump pointer to next char
  76. */
  77. #ifdef _MT
  78. if ( __ismbblead_mt(ptmbci, *(cp++)) )
  79. #else
  80. if ( _ismbblead(*(cp++)) )
  81. #endif
  82. cp++;
  83. }
  84. return(NULL);
  85. }
  86. #endif /* _MBCS */