Source code of Windows XP (NT5)
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.

94 lines
2.4 KiB

  1. /***
  2. *mbsrchr.c - Search for last occurence of character (MBCS)
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Search for last occurence of character (MBCS)
  8. *
  9. *Revision History:
  10. * 11-19-92 KRS Ported from 16-bit sources.
  11. * 08-20-93 CFW Change short params to int for 32-bit tree.
  12. * 10-05-93 GJF Replaced _CRTAPI1 with __cdecl.
  13. * 04-15-93 CFW Add _MB_CP_LOCK.
  14. * 05-09-94 CFW Optimize for SBCS.
  15. * 05-19-94 CFW Enable non-Win32.
  16. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  17. * 04-17-98 GJF Revised multithread support based on threadmbcinfo
  18. * structs
  19. *
  20. *******************************************************************************/
  21. #ifdef _MBCS
  22. #include <mtdll.h>
  23. #include <cruntime.h>
  24. #include <string.h>
  25. #include <mbdata.h>
  26. #include <mbctype.h>
  27. #include <mbstring.h>
  28. #include <stddef.h>
  29. /***
  30. * _mbsrchr - Search for last occurence of character (MBCS)
  31. *
  32. *Purpose:
  33. * Find the last occurrence of the specified character in
  34. * the supplied string. Handles MBCS chars/strings correctly.
  35. *
  36. *Entry:
  37. * unsigned char *str = string to search in
  38. * unsigned int c = character to search for
  39. *
  40. *Exit:
  41. * returns pointer to last occurrence of c in str
  42. * returns NULL if c not found
  43. *
  44. *Exceptions:
  45. *
  46. *******************************************************************************/
  47. unsigned char * __cdecl _mbsrchr(
  48. const unsigned char *str,
  49. unsigned int c
  50. )
  51. {
  52. char *r = NULL;
  53. unsigned int cc;
  54. #ifdef _MT
  55. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  56. if ( ptmbci != __ptmbcinfo )
  57. ptmbci = __updatetmbcinfo();
  58. if ( _ISNOTMBCP_MT(ptmbci) )
  59. #else
  60. if ( _ISNOTMBCP )
  61. #endif
  62. return strrchr(str, c);
  63. do {
  64. cc = *str;
  65. #ifdef _MT
  66. if ( __ismbblead_mt(ptmbci, cc) ) {
  67. #else
  68. if ( _ismbblead(cc) ) {
  69. #endif
  70. if(*++str) {
  71. if (c == ((cc<<8)|*str))
  72. r = (char *)str - 1;
  73. }
  74. else if(!r)
  75. /* return pointer to '\0' */
  76. r = (char *)str;
  77. }
  78. else if (c == cc)
  79. r = (char *)str;
  80. }
  81. while (*str++);
  82. return(r);
  83. }
  84. #endif /* _MBCS */