ReactOS 0.4.16-dev-927-g467dec4
mbsstr.cpp File Reference
#include <corecrt_internal.h>
#include <corecrt_internal_mbstring.h>
#include <locale.h>
#include <stddef.h>
#include <string.h>
Include dependency graph for mbsstr.cpp:

Go to the source code of this file.

Functions

_CONST_RETURN unsigned char *__cdecl _mbsstr_l (const unsigned char *str1, const unsigned char *str2, _locale_t plocinfo)
 
_CONST_RETURN unsigned char *__cdecl _mbsstr (const unsigned char *str1, const unsigned char *str2)
 

Function Documentation

◆ _mbsstr()

_CONST_RETURN unsigned char *__cdecl _mbsstr ( const unsigned char str1,
const unsigned char str2 
)

Definition at line 95 of file mbsstr.cpp.

99{
100 return _mbsstr_l(str1, str2, nullptr);
101}
_CONST_RETURN unsigned char *__cdecl _mbsstr_l(const unsigned char *str1, const unsigned char *str2, _locale_t plocinfo)
Definition: mbsstr.cpp:39

◆ _mbsstr_l()

_CONST_RETURN unsigned char *__cdecl _mbsstr_l ( const unsigned char str1,
const unsigned char str2,
_locale_t  plocinfo 
)

Definition at line 39 of file mbsstr.cpp.

44{
45 unsigned char *cp, *s1, *s2, *endp;
46 _LocaleUpdate _loc_update(plocinfo);
47
48 if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0)
49 return (unsigned char *)strstr((const char *)str1, (const char *)str2);
50
51 /* validation section */
52 _VALIDATE_RETURN(str2 != nullptr, EINVAL, 0);
53 if ( *str2 == '\0')
54 return (unsigned char *)str1;
55 _VALIDATE_RETURN(str1 != nullptr, EINVAL, 0);
56
57 cp = (unsigned char *) str1;
58 endp = (unsigned char *) (str1 + (strlen((const char *)str1) - strlen((const char *)str2)));
59
60 while (*cp && (cp <= endp))
61 {
62 s1 = cp;
63 s2 = (unsigned char *) str2;
64
65 /*
66 * MBCS: ok to ++ since doing equality comparison.
67 * [This depends on MBCS strings being "legal".]
68 */
69 while ( *s1 && *s2 && (*s1 == *s2) )
70 s1++, s2++;
71
72 if (!(*s2))
73 return(cp); /* success! */
74
75 /*
76 * bump pointer to next char
77 */
78 if ( _ismbblead_l(*(cp++), _loc_update.GetLocaleT()) )
79 {
80 /* don't move forward if we have leadbyte, EOS
81 means dud string was passed in.
82 Don't assert - too low level
83 */
84 if(*cp!='\0')
85 {
86 cp++;
87 }
88 }
89 }
90
91 return(nullptr);
92
93}
#define EINVAL
Definition: acclib.h:90
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define _ismbblead_l(_c, p)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
_locale_t plocinfo
Definition: ismbbyte.cpp:75
POINT cp
Definition: magnifier.c:59
struct S1 s1
struct S2 s2

Referenced by _mbsstr().