errno_t __cdecl _mbslwr_s_l( unsigned char *string, size_t sizeInBytes, _locale_t plocinfo ) { size_t stringlen; /* validation section */ _VALIDATE_RETURN_ERRCODE((string != nullptr && sizeInBytes > 0) || (string == nullptr && sizeInBytes == 0), EINVAL); if (string == nullptr) { /* nothing to do */ return 0; } stringlen = strnlen((char *)string, sizeInBytes); if (stringlen >= sizeInBytes) { _RESET_STRING(string, sizeInBytes); _RETURN_DEST_NOT_NULL_TERMINATED(string, sizeInBytes); } _FILL_STRING(string, sizeInBytes, stringlen + 1); unsigned char *cp, *dst; _LocaleUpdate _loc_update(plocinfo); for (cp = string, dst = string; *cp != '\0'; ++cp) { if (_ismbblead_l(*cp, _loc_update.GetLocaleT())) { int retval; unsigned char ret[4]; if ((retval = __acrt_LCMapStringA( _loc_update.GetLocaleT(), _loc_update.GetLocaleT()->mbcinfo->mblocalename, LCMAP_LOWERCASE, (const char *)cp, 2, (char *)ret, 2, _loc_update.GetLocaleT()->mbcinfo->mbcodepage, TRUE )) == 0 ) { errno = EILSEQ; _RESET_STRING(string, sizeInBytes); return errno; } *(dst++) = ret[0]; ++cp; if (retval > 1) { *(dst++) = ret[1]; } } else { /* single byte, macro version */ *(dst++) = (unsigned char) _mbbtolower_l(*cp, _loc_update.GetLocaleT()); } } /* null terminate the string */ *dst = '\0'; return 0; }
extern "C" int __cdecl _mbsicmp_l( const unsigned char *s1, const unsigned char *s2, _locale_t plocinfo ) { unsigned short c1, c2; _LocaleUpdate _loc_update(plocinfo); int retval; unsigned char szResult[4]; /* validation section */ _VALIDATE_RETURN(s1 != NULL, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(s2 != NULL, EINVAL, _NLSCMPERROR); if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) return _stricmp_l((const char *)s1, (const char *)s2, _loc_update.GetLocaleT()); for (;;) { c1 = *s1++; if ( _ismbblead_l(c1, _loc_update.GetLocaleT()) ) { if (*s1 == '\0') c1 = 0; else { retval = __crtLCMapStringA( _loc_update.GetLocaleT(), _loc_update.GetLocaleT()->mbcinfo->mblocalename, LCMAP_UPPERCASE, (LPCSTR)s1 - 1, 2, (LPSTR)szResult, 2, _loc_update.GetLocaleT()->mbcinfo->mbcodepage, TRUE ); if (retval == 1) c1 = szResult[0]; else if (retval == 2) c1 = (szResult[0] << 8) + szResult[1]; else { errno = EINVAL; return _NLSCMPERROR; } s1++; } } else c1 = _mbbtolower_l(c1, _loc_update.GetLocaleT()); c2 = *s2++; if ( _ismbblead_l(c2, _loc_update.GetLocaleT()) ) { if (*s2 == '\0') c2 = 0; else { retval = __crtLCMapStringA( _loc_update.GetLocaleT(), _loc_update.GetLocaleT()->mbcinfo->mblocalename, LCMAP_UPPERCASE, (LPCSTR)s2 - 1, 2, (LPSTR)szResult, 2, _loc_update.GetLocaleT()->mbcinfo->mbcodepage, TRUE ); if (retval == 1) c2 = szResult[0]; else if (retval == 2) c2 = (szResult[0] << 8) + szResult[1]; else { errno = EINVAL; return _NLSCMPERROR; } s2++; } } else c2 = _mbbtolower_l(c2, _loc_update.GetLocaleT()); if (c1 != c2) return( (c1 > c2) ? 1 : -1 ); if (c1 == 0) return(0); } }
int __cdecl _mbsnbicmp_l( const unsigned char *s1, const unsigned char *s2, size_t n, _locale_t plocinfo ) { unsigned short c1, c2; _LocaleUpdate _loc_update(plocinfo); if (n==0) return(0); if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) return _strnicmp((const char *)s1, (const char *)s2, n); /* validation section */ _VALIDATE_RETURN(s1 != nullptr, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(s2 != nullptr, EINVAL, _NLSCMPERROR); while (n--) { c1 = *s1++; if ( _ismbblead_l(c1, _loc_update.GetLocaleT()) ) { if (n==0) { c1 = 0; /* 'naked' lead - end of string */ c2 = _ismbblead_l(*s2, _loc_update.GetLocaleT()) ? 0 : *s2; goto test; } if (*s1 == '\0') c1 = 0; else { c1 = ((c1<<8) | *s1++); if ( ((c1 >= _MBUPPERLOW1_MT(_loc_update.GetLocaleT())) && (c1 <= _MBUPPERHIGH1_MT(_loc_update.GetLocaleT()))) ) c1 += _MBCASEDIFF1_MT(_loc_update.GetLocaleT()); else if ( ((c1 >= _MBUPPERLOW2_MT(_loc_update.GetLocaleT())) && (c1 <= _MBUPPERHIGH2_MT(_loc_update.GetLocaleT()))) ) c1 += _MBCASEDIFF2_MT(_loc_update.GetLocaleT()); } } else c1 = _mbbtolower_l(c1, _loc_update.GetLocaleT()); c2 = *s2++; if ( _ismbblead_l(c2, _loc_update.GetLocaleT()) ) { if (n==0) { c2 = 0; /* 'naked' lead - end of string */ goto test; } n--; if (*s2 == '\0') c2 = 0; else { c2 = ((c2<<8) | *s2++); if ( ((c2 >= _MBUPPERLOW1_MT(_loc_update.GetLocaleT())) && (c2 <= _MBUPPERHIGH1_MT(_loc_update.GetLocaleT()))) ) c2 += _MBCASEDIFF1_MT(_loc_update.GetLocaleT()); else if ( ((c2 >= _MBUPPERLOW2_MT(_loc_update.GetLocaleT())) && (c2 <= _MBUPPERHIGH2_MT(_loc_update.GetLocaleT()))) ) c2 += _MBCASEDIFF2_MT(_loc_update.GetLocaleT()); } } else c2 = _mbbtolower_l(c2, _loc_update.GetLocaleT()); test: if (c1 != c2) return( (c1 > c2) ? 1 : -1); if (c1 == 0) return(0); } return(0); }