diff --git a/.gitattributes b/.gitattributes index a21f013cc6420f8833426d03e59138c910fe44fd..b71794cc75fccd1904d060e5f5321af0f20b29c7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -231,3 +231,5 @@ miniMSVC/Windows[[:space:]]Kits/10/Lib/10.0.26100.0/um/x64/OneCoreUAP_apiset.Lib miniMSVC/Windows[[:space:]]Kits/10/Lib/10.0.26100.0/um/x64/OneCoreUAP_downlevel.Lib filter=lfs diff=lfs merge=lfs -text miniMSVC/Windows[[:space:]]Kits/10/Lib/10.0.26100.0/um/x64/OneCore.Lib filter=lfs diff=lfs merge=lfs -text miniMSVC/Windows[[:space:]]Kits/10/Lib/10.0.26100.0/um/x64/OneCoreUAP.Lib filter=lfs diff=lfs merge=lfs -text +miniMSVC/Windows[[:space:]]Kits/10/Lib/10.0.26100.0/um/x64/OneCore_apiset.Lib filter=lfs diff=lfs merge=lfs -text +miniCUDA124/bin/cusparse64_12.dll filter=lfs diff=lfs merge=lfs -text diff --git a/miniCUDA124/bin/cusparse64_12.dll b/miniCUDA124/bin/cusparse64_12.dll new file mode 100644 index 0000000000000000000000000000000000000000..d7ed7c3dfd9e6e15138b0a39c671f4df1e970109 --- /dev/null +++ b/miniCUDA124/bin/cusparse64_12.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f082a4b3896d1b9a3874834fd1385a18b895190d85e8da5ba3187c8c9eea75be +size 275632128 diff --git a/miniMSVC/Windows Kits/10/Lib/10.0.26100.0/um/x64/OneCore_apiset.Lib b/miniMSVC/Windows Kits/10/Lib/10.0.26100.0/um/x64/OneCore_apiset.Lib new file mode 100644 index 0000000000000000000000000000000000000000..b5664961efd2ead5e98c5085bea274968a54018e --- /dev/null +++ b/miniMSVC/Windows Kits/10/Lib/10.0.26100.0/um/x64/OneCore_apiset.Lib @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f9af7885991e573fd0e1393e8adfe1f1fad8d4c0d0ecd8b2a3651599c6c80d0 +size 2195416 diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbscpy_s_l.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbscpy_s_l.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e4ff70acb41bc4bd50e366f7c01088030148c64e --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbscpy_s_l.cpp @@ -0,0 +1,76 @@ +/*** +*mbscpy_s_l.c - Copy one string to another (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Copy one string to another (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +errno_t __cdecl _mbscpy_s_l(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, _LOCALE_ARG_DECL) +{ + unsigned char *p; + size_t available; + BOOL fIsLeadPrefix; + + /* validation section */ + _VALIDATE_STRING(_Dst, _SizeInBytes); + _VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes); + + _LOCALE_UPDATE; + if (_LOCALE_SHORTCUT_TEST) + { + return strcpy_s((char *)_Dst, _SizeInBytes, (const char *)_Src); + } + + p = _Dst; + available = _SizeInBytes; + while ((*p++ = *_Src++) != 0 && --available > 0) + { + } + + /* + * If we ran out of destination bytes then we did so before copying null. + * Only exception to that is if last mbc was invalid (leadbyte+null), which + * is treated as null. In that case clear the copied lead byte and return ok. + */ + + if (available == 0) + { + if (*_Src == 0) { + _ISMBBLEADPREFIX(fIsLeadPrefix,_Dst,p-1); + if (fIsLeadPrefix) + { + p[-1] = 0; + _RETURN_MBCS_ERROR; + } + } + _RESET_STRING(_Dst, _SizeInBytes); + _RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); + } + + /* + * Otherwise we have space left in the dst buffer and stopped copying because + * we saw a null in the src. If null is part of invalid MBC (lead byte + null) + * then clear the lead byte also. + */ + + _ISMBBLEADPREFIX(fIsLeadPrefix, _Dst, p-2); + if (fIsLeadPrefix && (p - 2) >= _Dst) + { + p[-2] = 0; + available++; + _FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); + _RETURN_MBCS_ERROR; + } + + _FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); + _RETURN_NO_ERROR; +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbscspn.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbscspn.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5d6eeebfd8fd63fcbdd64fb2d27d3739faacd647 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbscspn.cpp @@ -0,0 +1,143 @@ +/*** +*mbscspn.c - Find first string char in charset (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Find first string char in charset (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include +#include + +/*** +*ifndef _RETURN_PTR +* _mbscspn - Find first string char in charset (MBCS) +*else +* _mbspbrk - Find first string char in charset, pointer return (MBCS) +*endif +* +*Purpose: +* Returns maximum leading segment of string +* which consists solely of characters NOT from charset. +* Handles MBCS chars correctly. +* +*Entry: +* char *string = string to search in +* char *charset = set of characters to scan over +* +*Exit: +* +*ifndef _RETURN_PTR +* Returns the index of the first char in string +* that is in the set of characters specified by control. +* +* Returns 0, if string begins with a character in charset. +*else +* Returns pointer to first character in charset. +* +* Returns nullptr if string consists entirely of characters +* not from charset. +*endif +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +#ifndef _RETURN_PTR + +extern "C" size_t __cdecl _mbscspn_l( + const unsigned char *string, + const unsigned char *charset, + _locale_t plocinfo + ) +#else /* _RETURN_PTR */ + +extern "C" const unsigned char * __cdecl _mbspbrk_l( + const unsigned char *string, + const unsigned char *charset, + _locale_t plocinfo + ) +#endif /* _RETURN_PTR */ + +{ + unsigned char *p, *q; + _LocaleUpdate _loc_update(plocinfo); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) +#ifndef _RETURN_PTR + return strcspn((const char *)string, (const char *)charset); +#else /* _RETURN_PTR */ + return (const unsigned char *)strpbrk((const char *)string, (const char *)charset); +#endif /* _RETURN_PTR */ + + /* validation section */ +#ifndef _RETURN_PTR + _VALIDATE_RETURN(string != nullptr, EINVAL, 0); + _VALIDATE_RETURN(charset != nullptr, EINVAL, 0); +#else /* _RETURN_PTR */ + _VALIDATE_RETURN(string != nullptr, EINVAL, nullptr); + _VALIDATE_RETURN(charset != nullptr, EINVAL, nullptr); +#endif /* _RETURN_PTR */ + + /* loop through the string to be inspected */ + for (q = (unsigned char *)string; *q ; q++) { + + /* loop through the charset */ + for (p = (unsigned char *)charset; *p ; p++) { + + if ( _ismbblead_l(*p, _loc_update.GetLocaleT()) ) { + if (((*p == *q) && (p[1] == q[1])) || p[1] == '\0') + break; + p++; + } + else + if (*p == *q) + break; + } + + if (*p != '\0') /* end of charset? */ + break; /* no, match on this char */ + + if ( _ismbblead_l(*q, _loc_update.GetLocaleT()) ) + if (*++q == '\0') + break; + } + +#ifndef _RETURN_PTR + return((size_t) (q - string)); /* index */ +#else /* _RETURN_PTR */ + return((*q) ? q : nullptr); /* pointer */ +#endif /* _RETURN_PTR */ + +} + +#ifndef _RETURN_PTR + +extern "C" size_t (__cdecl _mbscspn)( + const unsigned char *string, + const unsigned char *charset + ) +#else /* _RETURN_PTR */ + +extern "C" const unsigned char * (__cdecl _mbspbrk)( + const unsigned char *string, + const unsigned char *charset + ) +#endif /* _RETURN_PTR */ + +{ +#ifndef _RETURN_PTR + return _mbscspn_l(string, charset, nullptr); +#else /* _RETURN_PTR */ + return _mbspbrk_l(string, charset, nullptr); +#endif /* _RETURN_PTR */ +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsdec.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsdec.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bfc9887302288b6d26ba791ca361a59e90b6dbcb --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsdec.cpp @@ -0,0 +1,109 @@ +/*** +*mbsdec.c - Move MBCS string pointer backward one charcter. +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Move MBCS string pointer backward one character. +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include + +/*** +*_mbsdec - Move MBCS string pointer backward one charcter. +* +*Purpose: +* Move the supplied string pointer backwards by one +* character. MBCS characters are handled correctly. +* +*Entry: +* const unsigned char *string = pointer to beginning of string +* const unsigned char *current = current char pointer (legal MBCS boundary) +* +*Exit: +* Returns pointer after moving it. +* Returns nullptr if string >= current. +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" unsigned char * __cdecl _mbsdec_l( + const unsigned char *string, + const unsigned char *current, + _locale_t plocinfo + ) +{ + const unsigned char *temp; + + /* validation section */ + _VALIDATE_RETURN(string != nullptr, EINVAL, nullptr); + _VALIDATE_RETURN(current != nullptr, EINVAL, nullptr); + + if (string >= current) + return(nullptr); + + _LocaleUpdate _loc_update(plocinfo); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return (unsigned char *)--current; + + temp = current - 1; + +/* There used to be an optimisation here: + * + * If (current-1) returns true from _ismbblead, it is a trail byte, because + * current is a known character start point, and so current-1 would have to be a + * legal single byte MBCS character, which a lead byte is not. Therefore, if so, + * return (current-2) because it must be the trailbyte's lead. + * + * if ( _ismbblead(*temp) ) + * return (unsigned char *)(temp - 1); + * + * But this is not a valid optimisation if you want to cope correctly with an + * MBCS string which is terminated by a leadbyte and a 0 byte, when you are passed + * an initial position pointing to the \0 at the end of the string. + * + * This optimisation is also invalid if you are passed a pointer to half-way + * through an MBCS pair. + * + * Neither of these are truly valid input conditions, but to ensure predictably + * correct behaviour in the presence of these conditions, we have removed + * the optimisation. + */ + +/* + * It is unknown whether (current - 1) is a single byte character or a + * trail. Now decrement temp until + * a) The beginning of the string is reached, or + * b) A non-lead byte (either single or trail) is found. + * The difference between (current-1) and temp is the number of non-single + * byte characters preceding (current-1). There are two cases for this: + * a) (current - temp) is odd, and + * b) (current - temp) is even. + * If odd, then there are an odd number of "lead bytes" preceding the + * single/trail byte (current - 1), indicating that it is a trail byte. + * If even, then there are an even number of "lead bytes" preceding the + * single/trail byte (current - 1), indicating a single byte character. + */ + while ( (string <= --temp) && (_ismbblead_l(*temp, _loc_update.GetLocaleT())) ) + ; + + return (unsigned char *)(current - 1 - ((current - temp) & 0x01) ); +} + +extern "C" unsigned char * (__cdecl _mbsdec)( + const unsigned char *string, + const unsigned char *current + ) +{ + return _mbsdec_l(string, current, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsicmp.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsicmp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..67bec271d402d6ffeb358fc67e7fe64a63da0303 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsicmp.cpp @@ -0,0 +1,142 @@ +/*** +*mbsicmp.c - Case-insensitive string comparision routine (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Case-insensitive string comparision routine (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include + +#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 + +/*** +* _mbsicmp - Case-insensitive string comparision routine (MBCS) +* +*Purpose: +* Compares two strings for ordinal order without regard to case. +* Strings are compared on a character basis, not a byte basis. +* +*Entry: +* char *s1, *s2 = strings to compare +* +*Exit: +* Returns <0 if s1 < s2 +* Returns 0 if s1 == s2 +* Returns >0 if s1 > s2 +* Returns _NLSCMPERROR if something went wrong +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +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 != nullptr, EINVAL, _NLSCMPERROR); + _VALIDATE_RETURN(s2 != nullptr, 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 = __acrt_LCMapStringA( + _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 = __acrt_LCMapStringA( + _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); + } +} + +extern "C" int (__cdecl _mbsicmp)( + const unsigned char *s1, + const unsigned char *s2 + ) +{ + return _mbsicmp_l(s1, s2, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsicoll.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsicoll.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5ba17259b0969bf44109c1584415df7be2202fb2 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsicoll.cpp @@ -0,0 +1,79 @@ +/*** +*mbsicoll.c - Collate MBCS strings, ignoring case +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Collate MBCS strings, ignoring case +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +/*** +* _mbsicoll - Collate MBCS strings, ignoring case +* +*Purpose: +* Collates two strings for lexical order (ignoring case). +* Strings are collated on a character basis, not a byte basis. +* +*Entry: +* char *s1, *s2 = strings to collate +* +*Exit: +* Returns <0 if s1 < s2 +* Returns 0 if s1 == s2 +* Returns >0 if s1 > s2 +* Returns _NLSCMPERROR is something went wrong +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" int __cdecl _mbsicoll_l( + const unsigned char *s1, + const unsigned char *s2, + _locale_t plocinfo + ) +{ + int ret; + _LocaleUpdate _loc_update(plocinfo); + + /* validation section */ + _VALIDATE_RETURN(s1 != nullptr, EINVAL, _NLSCMPERROR); + _VALIDATE_RETURN(s2 != nullptr, EINVAL, _NLSCMPERROR); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return _stricoll_l((const char *)s1, (const char *)s2, plocinfo); + + if ( 0 == (ret = __acrt_CompareStringA( + _loc_update.GetLocaleT(), + _loc_update.GetLocaleT()->mbcinfo->mblocalename, + SORT_STRINGSORT | NORM_IGNORECASE, + (LPCSTR)s1, + -1, + (LPSTR)s2, + -1, + _loc_update.GetLocaleT()->mbcinfo->mbcodepage )) ) + { + errno = EINVAL; + return _NLSCMPERROR; + } + + return ret - 2; + +} + +extern "C" int (__cdecl _mbsicoll)( + const unsigned char *s1, + const unsigned char *s2 + ) +{ + return _mbsicoll_l(s1, s2, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsinc.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsinc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7f1b57f3cc69e70c93b6381cf4beb022d36af5ac --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsinc.cpp @@ -0,0 +1,76 @@ +/*** +*mbsinc.c - Move MBCS string pointer ahead one charcter. +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Move MBCS string pointer ahead one character. +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 + +/*** +*_mbsinc - Move MBCS string pointer ahead one charcter. +* +*Purpose: +* Move the supplied string pointer ahead by one +* character. MBCS characters are handled correctly. +* +*Entry: +* const unsigned char *current = current char pointer (legal MBCS boundary) +* +*Exit: +* Returns pointer after moving it. +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" unsigned char * __cdecl _mbsinc_l( + const unsigned char *current, + _locale_t plocinfo + ) +{ + if ( (_ismbblead_l)(*(current++),plocinfo)) + { + /* don't move forward two if we get leadbyte, EOS + also don't assert here as we are too low level + */ + if(*current!='\0') + { + current++; + } + } + + return (unsigned char *)current; +} + +extern "C" unsigned char * (__cdecl _mbsinc)( + const unsigned char *current + ) +{ + /* validation section */ + _VALIDATE_RETURN(current != nullptr, EINVAL, nullptr); + + if ( _ismbblead(*(current++))) + { + /* don't move forward two if we get leadbyte, EOS + also don't assert here as we are too low level + */ + if(*current!='\0') + { + current++; + } + } + + return (unsigned char *)current; +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbslen.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbslen.cpp new file mode 100644 index 0000000000000000000000000000000000000000..83d51417d602f25850702e50cad514135c9ae4ad --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbslen.cpp @@ -0,0 +1,61 @@ +/*** +*mbslen.c - Find length of MBCS string +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Find length of MBCS string +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include + +/*** +* _mbslen - Find length of MBCS string +* +*Purpose: +* Find the length of the MBCS string (in characters). +* +*Entry: +* unsigned char *s = string +* +*Exit: +* Returns the number of MBCS chars in the string. +* +*Exceptions: +* +*******************************************************************************/ + +extern "C" size_t __cdecl _mbslen_l( + const unsigned char *s, + _locale_t plocinfo + ) +{ + int n; + _LocaleUpdate _loc_update(plocinfo); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return strlen((const char *)s); + + for (n = 0; *s; n++, s++) { + if ( _ismbblead_l(*s, _loc_update.GetLocaleT()) ) { + if (*++s == '\0') + break; + } + } + + return(n); +} + +extern "C" size_t (__cdecl _mbslen)( + const unsigned char *s + ) +{ + return _mbslen_l(s, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbslen_s.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbslen_s.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b3594b373342e1e923ac799a1aa76971d42510fb --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbslen_s.cpp @@ -0,0 +1,84 @@ +/*** +*mbslen_s.c - Find length of MBCS string +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Find length of MBCS string +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include + +/*** +* _mbsnlen - Find length of MBCS string +* +*Purpose: +* Find the length of the MBCS string (in characters). +* +*Entry: +* unsigned char *s = string +* size_t maxsize +* +*Exit: +* Returns the number of MBCS chars in the string. +* Only the first sizeInBytes bytes of the string are inspected: if the null +* terminator is not found, sizeInBytes is returned. +* If the string is null terminated in sizeInBytes bytes, the return value +* will always be less than sizeInBytes. +* Returns (size_t)-1 if something went wrong. +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +size_t __cdecl _mbsnlen_l( + const unsigned char *s, + size_t sizeInBytes, + _locale_t plocinfo + ) +{ + size_t n, size; + _LocaleUpdate _loc_update(plocinfo); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return strnlen((const char *)s, sizeInBytes); + + /* Note that we do not check if s == nullptr, because we do not + * return errno_t... + */ + + /* Note that sizeInBytes here is the number of bytes, not mb characters! */ + for (n = 0, size = 0; size < sizeInBytes && *s; n++, s++, size++) + { + if ( _ismbblead_l(*s, _loc_update.GetLocaleT()) ) + { + size++; + if (size >= sizeInBytes) + { + break; + } + if (*++s == '\0') + { + break; + } + } + } + + return (size >= sizeInBytes ? sizeInBytes : n); +} + +size_t __cdecl _mbsnlen( + const unsigned char *s, + size_t maxsize + ) +{ + return _mbsnlen_l(s,maxsize, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbslwr.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbslwr.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7234e29cf09169893eb1e0bea6db529a40dcc266 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbslwr.cpp @@ -0,0 +1,136 @@ +/*** +*mbslwr.c - Convert string lower case (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Convert string lower case (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include +#include + +#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 + +/*** +* _mbslwr - Convert string lower case (MBCS) +* +*Purpose: +* Convrts all the upper case characters in a string +* to lower case in place. MBCS chars are handled +* correctly. +* +*Entry: +* unsigned char *string = pointer to string +* +*Exit: +* Returns a pointer to the input string. +* Returns nullptr on error. +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +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; +} + +errno_t (__cdecl _mbslwr_s)( + unsigned char *string, + size_t sizeInBytes + ) +{ + return _mbslwr_s_l(string, sizeInBytes, nullptr); +} + +unsigned char * (__cdecl _mbslwr_l)( + unsigned char *string, + _locale_t plocinfo + ) +{ + return (_mbslwr_s_l(string, (string == nullptr ? 0 : (size_t)-1), plocinfo) == 0 ? string : nullptr); +} + +unsigned char * (__cdecl _mbslwr)( + unsigned char *string + ) +{ + return (_mbslwr_s_l(string, (string == nullptr ? 0 : (size_t)-1), nullptr) == 0 ? string : nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcat.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcat.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e2cb9d5b48d8c0ece7bc987e1af3b34d9cc8b3f3 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcat.cpp @@ -0,0 +1,116 @@ +/*** +*mbsnbcat.c - concatenate string2 onto string1, max length n bytes +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines mbsnbcat() - concatenate maximum of n bytes +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include + + +/*** +* _mbsnbcat - concatenate max cnt bytes onto dst +* +*Purpose: +* Concatenates src onto dst, with a maximum of cnt bytes copied. +* Handles 2-byte MBCS characters correctly. +* +*Entry: +* unsigned char *dst - string to concatenate onto +* unsigned char *src - string to concatenate from +* int cnt - number of bytes to copy +* +*Exit: +* returns dst, with src (at least part) concatenated on +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" unsigned char * __cdecl _mbsnbcat_l( + unsigned char *dst, + const unsigned char *src, + size_t cnt, + _locale_t plocinfo + ) +{ + unsigned char *start; + + if (!cnt) + return(dst); + + /* validation section */ + _VALIDATE_RETURN(dst != nullptr, EINVAL, nullptr); + _VALIDATE_RETURN(src != nullptr, EINVAL, nullptr); + + _LocaleUpdate _loc_update(plocinfo); + + _BEGIN_SECURE_CRT_DEPRECATION_DISABLE + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return (unsigned char *)strncat((char *)dst, (const char *)src, cnt); + _END_SECURE_CRT_DEPRECATION_DISABLE + + start = dst; + while (*dst++) + ; + --dst; // dst now points to end of dst string + + /* if last char in string is a lead byte, back up pointer */ + if ( dst!=start && _mbsbtype_l(start, (int) ((dst - start) - 1), _loc_update.GetLocaleT()) == _MBC_LEAD ) + { + --dst; + } + + /* copy over the characters */ + + while (cnt--) { + + if ( _ismbblead_l(*src, _loc_update.GetLocaleT()) ) { + *dst++ = *src++; + if (cnt == 0) { /* write null if cnt exhausted */ + dst[-1] = '\0'; + break; + } + cnt--; + if ((*dst++ = *src++)=='\0') { /* or if no trail byte */ + dst[-2] = '\0'; + break; + } + } + else if ((*dst++ = *src++) == '\0') + break; + + } + + if ( dst!=start && _mbsbtype_l(start, (int) ((dst - start) - 1), _loc_update.GetLocaleT()) == _MBC_LEAD ) + { + dst[-1] = '\0'; + } + else + { + *dst = '\0'; + } + + return(start); +} + +extern "C" unsigned char * (__cdecl _mbsnbcat)( + unsigned char *dst, + const unsigned char *src, + size_t cnt + ) +{ + _BEGIN_SECURE_CRT_DEPRECATION_DISABLE + return _mbsnbcat_l(dst, src, cnt, nullptr); + _END_SECURE_CRT_DEPRECATION_DISABLE +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcat_s.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcat_s.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b7a3e160bfa17e59e5cc0541624db20c56386b19 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcat_s.cpp @@ -0,0 +1,16 @@ +/*** +*mbsnbcat_s.c - concatenate string2 onto string1, max length n bytes +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines mbsnbcat_s() - concatenate maximum of n bytes +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include + +_REDIRECT_TO_L_VERSION_4(errno_t, _mbsnbcat_s, unsigned char *, size_t, const unsigned char *, size_t) diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcat_s_l.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcat_s_l.cpp new file mode 100644 index 0000000000000000000000000000000000000000..936378bff2fd39eb495673fe7f1b3d7c3cfaa4d6 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcat_s_l.cpp @@ -0,0 +1,21 @@ +/*** +*mbsnbcat_s_l.c - concatenate string2 onto string1, max length n bytes +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines mbsnbcat_s_l() - concatenate maximum of n bytes +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +#define _FUNC_NAME _mbsnbcat_s_l +#define _COUNT _CountInBytes +#define _COUNT_IN_BYTES 1 + +#include "mbsncat_s.inl" diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcmp.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcmp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7178442e0cd676bf2de984f5f30e0bc98834cb70 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcmp.cpp @@ -0,0 +1,107 @@ +/*** +*mbsnbcmp.c - Compare n bytes of two MBCS strings +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Compare n bytes of two MBCS strings +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 + +/*** +*int mbsnbcmp(s1, s2, n) - Compare n bytes of two MBCS strings +* +*Purpose: +* Compares up to n bytes of two strings for ordinal order. +* +* UTF-8 and SBCS are merely compared in byte order. +* DBCS are compared by codepoint to ensure double byte chars sort last +* +*Entry: +* unsigned char *s1, *s2 = strings to compare +* size_t n = maximum number of bytes to compare +* +*Exit: +* Returns <0 if s1 < s2 +* Returns 0 if s1 == s2 +* Returns >0 if s1 > s2 +* Returns _NLSCMPERROR is something went wrong +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" int __cdecl _mbsnbcmp_l( + const unsigned char *s1, + const unsigned char *s2, + size_t n, + _locale_t plocinfo + ) +{ + unsigned short c1, c2; + + if (n==0) + return(0); + + _LocaleUpdate _loc_update(plocinfo); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return strncmp((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; + } + c1 = ( (*s1 == '\0') ? 0 : ((c1<<8) | *s1++) ); + } + + c2 = *s2++; + if ( _ismbblead_l(c2, _loc_update.GetLocaleT()) ) + { + if (n==0) + { + c2 = 0; /* 'naked' lead - end of string */ + goto test; + } + --n; + c2 = ( (*s2 == '\0') ? 0 : ((c2<<8) | *s2++) ); + } +test: + if (c1 != c2) + return( (c1 > c2) ? 1 : -1); + + if (c1 == 0) + return(0); + } + + return(0); +} + +extern "C" int (__cdecl _mbsnbcmp)( + const unsigned char *s1, + const unsigned char *s2, + size_t n + ) +{ + return _mbsnbcmp_l(s1, s2, n, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcnt.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcnt.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8cbf684dcaeb25e98af4e24f19db7b73361aa4dc --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcnt.cpp @@ -0,0 +1,71 @@ +/*** +*mbsnbcnt.c - Returns byte count of MBCS string +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Returns byte count of MBCS string +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +/*** +* _mbsnbcnt - Returns byte count of MBCS string +* +*Purpose: +* Returns the number of bytes between the start of the supplied +* string and the char count supplied. That is, this routine +* indicates how many bytes are in the first "ccnt" characters +* of the string. +* +*Entry: +* unsigned char *string = pointer to string +* unsigned int ccnt = number of characters to scan +* +*Exit: +* Returns number of bytes between string and ccnt. +* +* If the end of the string is encountered before ccnt chars were +* scanned, then the length of the string in bytes is returned. +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" size_t __cdecl _mbsnbcnt_l( + const unsigned char *string, + size_t ccnt, + _locale_t plocinfo + ) +{ + unsigned char *p; + _LocaleUpdate _loc_update(plocinfo); + + /* validation section */ + _VALIDATE_RETURN(string != nullptr || ccnt == 0, EINVAL, 0); + + for (p = (unsigned char *)string; (ccnt-- && *p); p++) { + if ( _ismbblead_l(*p, _loc_update.GetLocaleT()) ) { + if (*++p == '\0') { + --p; + break; + } + } + } + + return ((size_t) ((char *)p - (char *)string)); +} + +extern "C" size_t (__cdecl _mbsnbcnt)( + const unsigned char *string, + size_t ccnt + ) +{ + return _mbsnbcnt_l(string, ccnt, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcol.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcol.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca6e18baede2321e446470097d31ed64c49a4bb2 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcol.cpp @@ -0,0 +1,86 @@ +/*** +*mbsnbcol.c - Collate n bytes of two MBCS strings +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Collate n bytes of two MBCS strings +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include + +/*** +* _mbsnbcoll(s1, s2, n) - Collate n bytes of two MBCS strings +* +*Purpose: +* Collates up to n bytes of two strings for lexical order. +* +*Entry: +* unsigned char *s1, *s2 = strings to collate +* size_t n = maximum number of bytes to collate +* +*Exit: +* Returns <0 if s1 < s2 +* Returns 0 if s1 == s2 +* Returns >0 if s1 > s2 +* Returns _NLSCMPERROR is something went wrong +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" int __cdecl _mbsnbcoll_l( + const unsigned char *s1, + const unsigned char *s2, + size_t n, + _locale_t plocinfo + ) +{ + int ret; + + if (n == 0) + return 0; + + /* validation section */ + _VALIDATE_RETURN(s1 != nullptr, EINVAL, _NLSCMPERROR); + _VALIDATE_RETURN(s2 != nullptr, EINVAL, _NLSCMPERROR); + _VALIDATE_RETURN(n <= INT_MAX, EINVAL, _NLSCMPERROR); + + _LocaleUpdate _loc_update(plocinfo); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return _strncoll_l((const char *)s1, (const char *)s2, n, plocinfo); + + if ( 0 == (ret = __acrt_CompareStringA(_loc_update.GetLocaleT(), + _loc_update.GetLocaleT()->mbcinfo->mblocalename, + SORT_STRINGSORT, + (const char *)s1, + (int)n, + (char *)s2, + (int)n, + _loc_update.GetLocaleT()->mbcinfo->mbcodepage )) ) + { + errno = EINVAL; + return _NLSCMPERROR; + } + + return ret - 2; + +} + +extern "C" int (__cdecl _mbsnbcoll)( + const unsigned char *s1, + const unsigned char *s2, + size_t n + ) +{ + return _mbsnbcoll_l(s1, s2, n, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcpy.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcpy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a5f8db4f3e19685f4e61f0f3f7c37531b85a691e --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcpy.cpp @@ -0,0 +1,103 @@ +/*** +*mbsnbcpy.c - Copy one string to another, n bytes only (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Copy one string to another, n bytes only (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 + +/*** +* _mbsnbcpy - Copy one string to another, n bytes only (MBCS) +* +*Purpose: +* Copies exactly cnt bytes from src to dst. If strlen(src) < cnt, the +* remaining character are padded with null bytes. If strlen >= cnt, no +* terminating null byte is added. 2-byte MBCS characters are handled +* correctly. +* +*Entry: +* unsigned char *dst = destination for copy +* unsigned char *src = source for copy +* int cnt = number of bytes to copy +* +*Exit: +* returns dst = destination of copy +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +#pragma warning(suppress:6101) // Returning uninitialized memory '*dst'. A successful path through the function does not set the named _Out_ parameter. +unsigned char * __cdecl _mbsnbcpy_l( + unsigned char *dst, + const unsigned char *src, + size_t cnt, + _locale_t plocinfo + ) +{ + + unsigned char *start = dst; + _LocaleUpdate _loc_update(plocinfo); + + /* validation section */ + _VALIDATE_RETURN(dst != nullptr || cnt == 0, EINVAL, nullptr); + _VALIDATE_RETURN(src != nullptr || cnt == 0, EINVAL, nullptr); + + _BEGIN_SECURE_CRT_DEPRECATION_DISABLE + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) +#pragma warning(suppress:__WARNING_BANNED_API_USAGE) + return (unsigned char *)strncpy((char *)dst, (const char *)src, cnt); + _END_SECURE_CRT_DEPRECATION_DISABLE + + while (cnt) { + + cnt--; + if ( _ismbblead_l(*src, _loc_update.GetLocaleT()) ) { + *dst++ = *src++; + if (!cnt) { + dst[-1] = '\0'; + break; + } + cnt--; + if ((*dst++ = *src++) == '\0') { + dst[-2] = '\0'; + break; + } + } + + else + if ((*dst++ = *src++) == '\0') + break; + + } + + /* pad with nulls as needed */ + + while (cnt--) + *dst++ = '\0'; + +#pragma warning(suppress:__WARNING_POSTCONDITION_NULLTERMINATION_VIOLATION) // 26036 + return start; +} +unsigned char * (__cdecl _mbsnbcpy)( + unsigned char *dst, + const unsigned char *src, + size_t cnt + ) +{ + _BEGIN_SECURE_CRT_DEPRECATION_DISABLE + return _mbsnbcpy_l(dst, src, cnt, nullptr); + _END_SECURE_CRT_DEPRECATION_DISABLE +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcpy_s.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcpy_s.cpp new file mode 100644 index 0000000000000000000000000000000000000000..055f38cc3d229b04fd7885a867278d37813f1edb --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcpy_s.cpp @@ -0,0 +1,16 @@ +/*** +*mbsnbcpy_s.c - Copy one string to another, n bytes only (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Copy one string to another, n bytes only (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include + +_REDIRECT_TO_L_VERSION_4(errno_t, _mbsnbcpy_s, unsigned char *, size_t, const unsigned char *, size_t) diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcpy_s_l.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcpy_s_l.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a83547aa22f9e6779377e7fc6f53ff579c0a312 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbcpy_s_l.cpp @@ -0,0 +1,21 @@ +/*** +*mbsnbcpy_s_l.c - Copy one string to another, n bytes only (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Copy one string to another, n bytes only (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +#define _FUNC_NAME _mbsnbcpy_s_l +#define _COUNT _CountInBytes +#define _COUNT_IN_BYTES 1 + +#include "mbsncpy_s.inl" diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbicm.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbicm.cpp new file mode 100644 index 0000000000000000000000000000000000000000..38e1a166bf2b723b5509e5eb0d5441e786a191a7 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbicm.cpp @@ -0,0 +1,133 @@ +/*** +*mbsnbicmp.c - Compare n bytes of strings, ignoring case (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Compare n bytes of strings, ignoring case (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 + +/*** +* _mbsnbicmp - Compare n bytes of strings, ignoring case (MBCS) +* +*Purpose: +* Compares up to n bytes of two strings for ordinal order. +* Strings are compared on a character basis, not a byte basis. +* Case of characters is not considered. +* +*Entry: +* unsigned char *s1, *s2 = strings to compare +* size_t n = maximum number of bytes to compare +* +*Exit: +* Returns <0 if s1 < s2 +* Returns 0 if s1 == s2 +* Returns >0 if s1 > s2 +* Returns _NLSCMPERROR is something went wrong +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +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); +} + +int (__cdecl _mbsnbicmp)( + const unsigned char *s1, + const unsigned char *s2, + size_t n + ) +{ + return _mbsnbicmp_l(s1, s2, n, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbico.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbico.cpp new file mode 100644 index 0000000000000000000000000000000000000000..584ec9db9532ff2dc82d9b9a486c358e9f590763 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbico.cpp @@ -0,0 +1,82 @@ +/*** +*mbsnbico.c - Collate n bytes of strings, ignoring case (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Collate n bytes of strings, ignoring case (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + + +/*** +* _mbsnbicoll - Collate n bytes of strings, ignoring case (MBCS) +* +*Purpose: +* Collates up to n bytes of two strings for lexical order. +* Strings are collated on a character basis, not a byte basis. +* Case of characters is not considered. +* +*Entry: +* unsigned char *s1, *s2 = strings to collate +* size_t n = maximum number of bytes to collate +* +*Exit: +* Returns <0 if s1 < s2 +* Returns 0 if s1 == s2 +* Returns >0 if s1 > s2 +* Returns _NLSCMPERROR is something went wrong +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" int __cdecl _mbsnbicoll_l( + const unsigned char *s1, + const unsigned char *s2, + size_t n, + _locale_t plocinfo + ) +{ + int ret; + _LocaleUpdate _loc_update(plocinfo); + + if (n == 0) + return 0; + + /* validation section */ + _VALIDATE_RETURN(s1 != nullptr, EINVAL, _NLSCMPERROR); + _VALIDATE_RETURN(s2 != nullptr, EINVAL, _NLSCMPERROR); + _VALIDATE_RETURN(n <= INT_MAX, EINVAL, _NLSCMPERROR); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return _strnicoll_l((const char *)s1, (const char *)s2, n, plocinfo); + + if ( 0 == (ret = __acrt_CompareStringA(_loc_update.GetLocaleT(), + _loc_update.GetLocaleT()->mbcinfo->mblocalename, + SORT_STRINGSORT | NORM_IGNORECASE, + (const char *)s1, + (int)n, + (char *)s2, + (int)n, + _loc_update.GetLocaleT()->mbcinfo->mbcodepage )) ) + return _NLSCMPERROR; + + return ret - 2; + +} +extern "C" int __cdecl _mbsnbicoll( + const unsigned char *s1, + const unsigned char *s2, + size_t n + ) +{ + return _mbsnbicoll_l(s1, s2, n, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbset.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbset.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b9eec869bacc369ca84208ea2f33f3a461f8a766 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbset.cpp @@ -0,0 +1,136 @@ +/*** +*mbsnbset.c - Sets first n bytes of string to given character (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Sets first n bytes of string to given character (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +/*** +* _mbsnbset - Sets first n bytes of string to given character (MBCS) +* +*Purpose: +* Sets the first n bytes of string to the supplied +* character value. If the length of string is less than n, +* the length of string is used in place of n. Handles +* MBCS chars correctly. +* +* There are several factors that make this routine complicated: +* (1) The fill value may be 1 or 2 bytes long. +* (2) The fill operation may end by hitting the count value +* or by hitting the end of the string. +* (3) A null terminating char is NOT placed at the end of +* the string. +* +* Cases to be careful of (both of these can occur at once): +* (1) Leaving an "orphaned" trail byte in the string (e.g., +* overwriting a lead byte but not the corresponding trail byte). +* (2) Writing only the 1st byte of a 2-byte fill value because the +* end of string was encountered. +* +*Entry: +* unsigned char *string = string to modify +* unsigned int val = value to fill string with +* size_t count = count of characters to fill +* +* +*Exit: +* Returns string = now filled with char val +* +*Uses: +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" unsigned char * __cdecl _mbsnbset_l( + unsigned char *string, + unsigned int val, + size_t count, + _locale_t plocinfo + ) +{ + unsigned char *start = string; + unsigned char highval, lowval; + _LocaleUpdate _loc_update(plocinfo); + +_BEGIN_SECURE_CRT_DEPRECATION_DISABLE + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return (unsigned char *)_strnset((char *)string, val, count); +_END_SECURE_CRT_DEPRECATION_DISABLE + + /* validation section */ + _VALIDATE_RETURN(string != nullptr || count == 0, EINVAL, nullptr); + + /* + * leadbyte flag indicates if the last byte we overwrote was + * a lead byte or not. + */ + + highval = static_cast(val >> 8); + if (highval) + { + /* double byte value */ + + lowval = (unsigned char)(val & 0x00ff); + + if(lowval=='\0') + { + _ASSERTE(("invalid MBCS pair passed to mbsnbset",0)); + + /* Ideally we would return nullptr here and signal an error + condition. But since this function has no other + error modes, there would be a good chance of crashing + the caller. So instead we fill the string with spaces + to ensure that no information leaks through + unexpectedly. Anyway, we do set errno to EINVAL. + */ + errno = EINVAL; + lowval=highval=' '; + } + + while ((count--) && *string) { + + /* pad with ' ' if no room for both bytes -- odd len */ + if ((!count--) || (!*(string+1))) { + *string = ' '; + break; + } + + *string++ = highval; + *string++ = lowval; + } + } + + else { + /* single byte value */ + + while (count-- && *string) { + *string++ = (unsigned char)val; + } + + } + + return( start ); +} + +extern "C" unsigned char * (__cdecl _mbsnbset)( + unsigned char *string, + unsigned int val, + size_t count + ) +{ +_BEGIN_SECURE_CRT_DEPRECATION_DISABLE + return _mbsnbset_l(string, val, count, nullptr); +_END_SECURE_CRT_DEPRECATION_DISABLE +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbset_s.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbset_s.cpp new file mode 100644 index 0000000000000000000000000000000000000000..922c443c87fd52fb9296b1a893e6692673607136 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbset_s.cpp @@ -0,0 +1,17 @@ +/*** +*mbsnbset_s.c - Sets first n bytes of string to given character (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Sets first n bytes of string to given character (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +_REDIRECT_TO_L_VERSION_4(errno_t, _mbsnbset_s, unsigned char *, size_t, unsigned int, size_t) diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbset_s_l.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbset_s_l.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b4ce6ed0babed33321bee094e40643d217ceddd9 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnbset_s_l.cpp @@ -0,0 +1,21 @@ +/*** +*mbsset_s_l.c - Sets first n bytes of string to given character (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Sets first n bytes of string to given character (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +#define _FUNC_NAME _mbsnbset_s_l +#define _COUNT _CountInBytes +#define _COUNT_IN_BYTES 1 + +#include "mbsnset_s.inl" diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2fbdbcb47cd21a3de0df8d9be1b7e95186fdf131 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat.cpp @@ -0,0 +1,110 @@ +/*** +*mbsncat.c - concatenate string2 onto string1, max length n +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines mbsncat() - concatenate maximum of n characters +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + + +/*** +* _mbsncat - concatenate max cnt characters onto dst +* +*Purpose: +* Concatenates src onto dst, with a maximum of cnt characters copied. +* Handles 2-byte MBCS characters correctly. +* +*Entry: +* unsigned char *dst - string to concatenate onto +* unsigned char *src - string to concatenate from +* int cnt - number of characters to copy +* +*Exit: +* returns dst, with src (at least part) concatenated on +* +*Exceptions: +* +*******************************************************************************/ + +extern "C" unsigned char * __cdecl _mbsncat_l( + unsigned char *dst, + const unsigned char *src, + size_t cnt, + _locale_t plocinfo + ) +{ + unsigned char *start; + + if (!cnt) + return(dst); + + /* validation section */ + _VALIDATE_RETURN(dst != nullptr, EINVAL, nullptr); + _VALIDATE_RETURN(src != nullptr, EINVAL, nullptr); + + _LocaleUpdate _loc_update(plocinfo); + + _BEGIN_SECURE_CRT_DEPRECATION_DISABLE + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return (unsigned char *)strncat((char *)dst, (const char *)src, cnt); + _END_SECURE_CRT_DEPRECATION_DISABLE + + start = dst; + while (*dst++) + ; + --dst; // dst now points to end of dst string + + + /* if last char in string is a lead byte, back up pointer */ + + if ( _ismbslead_l(start, dst, _loc_update.GetLocaleT()) ) + --dst; + + /* copy over the characters */ + + while (cnt--) { + if ( _ismbblead_l(*src, _loc_update.GetLocaleT()) ) { + *dst++ = *src++; + if ((*dst++ = *src++) == '\0') { + dst[-2] = '\0'; + break; + } + } + + else if ((*dst++ = *src++) == '\0') + break; + + } + + /* enter final nul, if necessary */ + if ( dst!=start && _mbsbtype_l(start, (int) ((dst - start) - 1), _loc_update.GetLocaleT()) == _MBC_LEAD ) + { + dst[-1] = '\0'; + } + else + { + *dst = '\0'; + } + + return(start); +} + +extern "C" unsigned char * (__cdecl _mbsncat)( + unsigned char *dst, + const unsigned char *src, + size_t cnt + ) +{ + _BEGIN_SECURE_CRT_DEPRECATION_DISABLE + return _mbsncat_l(dst, src, cnt, nullptr); + _END_SECURE_CRT_DEPRECATION_DISABLE +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat_s.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat_s.cpp new file mode 100644 index 0000000000000000000000000000000000000000..605a4dee72262308f1815ddb174139819fb59b4c --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat_s.cpp @@ -0,0 +1,16 @@ +/*** +*mbsncat_s.c - concatenate string2 onto string1, max length n +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines mbsncat_s() - concatenate maximum of n characters +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include + +_REDIRECT_TO_L_VERSION_4(errno_t, _mbsncat_s, unsigned char *, size_t, const unsigned char *, size_t) diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat_s.inl b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat_s.inl new file mode 100644 index 0000000000000000000000000000000000000000..871b178b0a3ee6737d7df08962557c7865d8106d --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat_s.inl @@ -0,0 +1,203 @@ +/*** +*mbsncat_s.inl - general implementation of _mbsncat_s and _mbsnbcat_s +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* This file contains the general algorithm for _mbsncat_s and _mbsnbcat_s. +* +****/ + +errno_t __cdecl _FUNC_NAME(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _COUNT, _LOCALE_ARG_DECL) +{ + unsigned char *p; + size_t available; + BOOL fIsLeadPrefix; + BOOL fFoundInvalidMBC; + + fFoundInvalidMBC = FALSE; + + if (_COUNT == 0 && _Dst == nullptr && _SizeInBytes == 0) + { + /* this case is allowed; nothing to do */ + _RETURN_NO_ERROR; + } + + /* validation section */ + _VALIDATE_STRING(_Dst, _SizeInBytes); + if (_COUNT != 0) + { + _VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes); + } + + _LOCALE_UPDATE; + if (_LOCALE_SHORTCUT_TEST) + { + return strncat_s((char *)_Dst, _SizeInBytes, (const char *)_Src, _COUNT); + } + + p = _Dst; + available = _SizeInBytes; + while (available > 0 && *p != 0) + { + p++; + available--; + } + + /* + * Ran out of room while looking for end of dst string. + * p points 1 past end of buffer. We can't look past + * end of buffer so can't tell if dst ended with an + * invalid mbc. + */ + + if (available == 0) + { + _RESET_STRING(_Dst, _SizeInBytes); + _RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes); + } + + + if (available < _SizeInBytes) + { + /* + * Dst may have terminated with an invalid MBCS, in that case we clear + * the bogus lead byte. + */ + fIsLeadPrefix = FALSE; + _ISMBBLEADPREFIX(fIsLeadPrefix, _Dst, &p[-1]); + if (fIsLeadPrefix) { + /* the original string ended with a lead byte: we remove it */ + p--; + *p = 0; + available++; + fFoundInvalidMBC = TRUE; + } + } + + if (_COUNT == _TRUNCATE) + { + while ((*p++ = *_Src++) != 0 && --available > 0) + { + } + } + else + { +#if _COUNT_IN_BYTES + while (_COUNT > 0 && (*p++ = *_Src++) != 0 && --available > 0) + { + _COUNT--; + } +#else /* _COUNT_IN_BYTES */ + while (_COUNT > 0) + { + if (_ISMBBLEAD(*_Src)) + { + if (_Src[1] == 0) + { + /* the source string ended with a lead byte: we remove it */ + *p = 0; + fFoundInvalidMBC = TRUE; + break; + } + if (available <= 2) + { + /* not enough space */ + available = 0; + break; + } + *p++ = *_Src++; + *p++ = *_Src++; + available -= 2; + } + else + { + if ((*p++ = *_Src++) == 0 || --available == 0) + { + break; + } + } + _COUNT--; + } +#endif /* _COUNT_IN_BYTES */ + if (_COUNT == 0) + { + *p++ = 0; + } + } + + if (available == 0) + { +#if _COUNT_IN_BYTES + /* + * defined(_COUNT_IN_BYTES) loop does not track mbc context, + * so we must iterate backwards to discover character context. + */ + if (*_Src == 0 || _COUNT == 1) + { + _ISMBBLEADPREFIX(fIsLeadPrefix, _Dst, &p[-1]); + if (fIsLeadPrefix) + { + /* the source string ended with a lead byte: we remove it */ + p[-1] = 0; + _RETURN_MBCS_ERROR; + } + } +#endif /* _COUNT_IN_BYTES */ + + /* + * _COUNT == _TRUNCATE loop terminated because available became 0. + * This means that we copied at least one character, and it wasn't + * a null. If this last character acted as a lead then overwrite + * it with null. Do not set the mbcs error in this case, due that the + * user cannot predict this case and he/she's only asking for truncation. + */ + if (_COUNT == _TRUNCATE) + { + if (fFoundInvalidMBC) + { + _SET_MBCS_ERROR; + } + + if (_SizeInBytes > 1) + { + fIsLeadPrefix = FALSE; + _ISMBBLEADPREFIX(fIsLeadPrefix, _Dst, &_Dst[_SizeInBytes - 2]); + if (fIsLeadPrefix) + { + _Dst[_SizeInBytes - 2] = 0; + _FILL_BYTE(_Dst[_SizeInBytes - 1]); + _RETURN_TRUNCATE; + } + } + + _Dst[_SizeInBytes - 1] = 0; + + _RETURN_TRUNCATE; + } + _RESET_STRING(_Dst, _SizeInBytes); + _RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); + } +#if _COUNT_IN_BYTES + if (available < _SizeInBytes) + { + _ISMBBLEADPREFIX(fIsLeadPrefix, _Dst, &p[-2]); + if (fIsLeadPrefix) + { + /* the source string ended with a lead byte: we remove it */ + p[-2] = 0; + available++; + fFoundInvalidMBC = TRUE; + } + } +#endif /* _COUNT_IN_BYTES */ + _FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); + + if (fFoundInvalidMBC) + { + _RETURN_MBCS_ERROR; + } + + _RETURN_NO_ERROR; +} + diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat_s_l.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat_s_l.cpp new file mode 100644 index 0000000000000000000000000000000000000000..279af2da40481988ed4c7ff9a2a570ebca2c2768 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncat_s_l.cpp @@ -0,0 +1,21 @@ +/*** +*mbsncat_s_l.c - concatenate string2 onto string1, max length n +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines mbsncat_s_l() - concatenate maximum of n characters +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +#define _FUNC_NAME _mbsncat_s_l +#define _COUNT _CountInChars +#define _COUNT_IN_BYTES 0 + +#include "mbsncat_s.inl" diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnccnt.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnccnt.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8321650c87d691410969ff2d5159e79bdb6d624d --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnccnt.cpp @@ -0,0 +1,67 @@ +/*** +*mbsnccnt.c - Return char count of MBCS string +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Return char count of MBCS string +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +/*** +* _mbsnccnt - Return char count of MBCS string +* +*Purpose: +* Returns the number of chars between the start of the supplied +* string and the byte count supplied. That is, this routine +* indicates how many chars are in the first "bcnt" bytes +* of the string. +* +*Entry: +* const unsigned char *string = pointer to string +* unsigned int bcnt = number of bytes to scan +* +*Exit: +* Returns number of chars between string and bcnt. +* +* If the end of the string is encountered before bcnt chars were +* scanned, then the length of the string in chars is returned. +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" size_t __cdecl _mbsnccnt_l( + const unsigned char *string, + size_t bcnt, + _locale_t plocinfo + ) +{ + size_t n; + _LocaleUpdate _loc_update(plocinfo); + + _VALIDATE_RETURN(string != nullptr || bcnt == 0, EINVAL, 0); + + for (n = 0; (bcnt-- && *string); n++, string++) { + if ( _ismbblead_l(*string, _loc_update.GetLocaleT()) ) { + if ( (!bcnt--) || (*++string == '\0')) + break; + } + } + + return(n); +} +extern "C" size_t (__cdecl _mbsnccnt)( + const unsigned char *string, + size_t bcnt + ) +{ + return _mbsnccnt_l(string, bcnt, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncmp.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncmp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..880fb94373c515e24901c4f6f7b35acd6a2bf822 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncmp.cpp @@ -0,0 +1,92 @@ +/*** +*mbsncmp.c - Compare n characters of two MBCS strings +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Compare n characters of two MBCS strings +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 + +/*** +*int mbsncmp(s1, s2, n) - Compare n characters of two MBCS strings +* +*Purpose: +* Compares up to n characters of two strings for ordinal order. +* Strings are compared on a character basis, not a byte basis. +* +* UTF-8 and SBCS are merely compared in byte order. +* DBCS are compared by codepoint to ensure double byte chars sort last +* +*Entry: +* unsigned char *s1, *s2 = strings to compare +* size_t n = maximum number of characters to compare +* +*Exit: +* Returns <0 if s1 < s2 +* Returns 0 if s1 == s2 +* Returns >0 if s1 > s2 +* Returns _NLSCMPERROR is something went wrong +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" int __cdecl _mbsncmp_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 strncmp((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()) ) + c1 = ( (*s1 == '\0') ? 0 : ((c1<<8) | *s1++) ); + + c2 = *s2++; + if ( _ismbblead_l(c2, _loc_update.GetLocaleT()) ) + c2 = ( (*s2 == '\0') ? 0 : ((c2<<8) | *s2++) ); + + if (c1 != c2) + return( (c1 > c2) ? 1 : -1); + + if (c1 == 0) + return(0); + } + + return(0); +} + +extern "C" int (__cdecl _mbsncmp)( + const unsigned char *s1, + const unsigned char *s2, + size_t n + ) +{ + return _mbsncmp_l(s1, s2, n, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncoll.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncoll.cpp new file mode 100644 index 0000000000000000000000000000000000000000..22d8a894792c9157d58108b9376c71de8b683efb --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncoll.cpp @@ -0,0 +1,91 @@ +/*** +*mbsncol.c - Collate n characters of two MBCS strings +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Collate n characters of two MBCS strings +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include + +/*** +* _mbsncoll(s1, s2, n) - Collate n characters of two MBCS strings +* +*Purpose: +* Collates up to n charcters of two strings for lexical order. +* Strings are collated on a character basis, not a byte basis. +* +*Entry: +* unsigned char *s1, *s2 = strings to collate +* size_t n = maximum number of characters to collate +* +*Exit: +* Returns <0 if s1 < s2 +* Returns 0 if s1 == s2 +* Returns >0 if s1 > s2 +* Returns _NLSCMPERROR is something went wrong +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" int __cdecl _mbsncoll_l( + const unsigned char *s1, + const unsigned char *s2, + size_t n, + _locale_t plocinfo + ) +{ + int ret; + size_t bcnt1, bcnt2; + _LocaleUpdate _loc_update(plocinfo); + + if (n == 0) + return 0; + + /* validation section */ + _VALIDATE_RETURN(s1 != nullptr, EINVAL, _NLSCMPERROR); + _VALIDATE_RETURN(s2 != nullptr, EINVAL, _NLSCMPERROR); + _VALIDATE_RETURN(n <= INT_MAX, EINVAL, _NLSCMPERROR); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return _strncoll_l((const char *)s1, (const char *)s2, n, plocinfo); + + bcnt1 = _mbsnbcnt_l(s1, n, _loc_update.GetLocaleT()); + bcnt2 = _mbsnbcnt_l(s2, n, _loc_update.GetLocaleT()); + + if ( 0 == (ret = __acrt_CompareStringA( + _loc_update.GetLocaleT(), + _loc_update.GetLocaleT()->mbcinfo->mblocalename, + SORT_STRINGSORT, + (const char *)s1, + (int)bcnt1, + (char *)s2, + (int)bcnt2, + _loc_update.GetLocaleT()->mbcinfo->mbcodepage )) ) + { + errno = EINVAL; + return _NLSCMPERROR; + } + + return ret - 2; + +} + +extern "C" int (__cdecl _mbsncoll)( + const unsigned char *s1, + const unsigned char *s2, + size_t n + ) +{ + return _mbsncoll_l(s1, s2, n, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..01f649c604c689d235e81a2cd4fd421730968ea3 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy.cpp @@ -0,0 +1,96 @@ +/*** +*mbsncpy.c - Copy one string to another, n chars only (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Copy one string to another, n chars only (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +#pragma warning(disable:__WARNING_INCORRECT_VALIDATION __WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26014 26018 + +/*** +* _mbsncpy - Copy one string to another, n chars only (MBCS) +* +*Purpose: +* Copies exactly cnt character from src to dst. If strlen(src) < cnt, the +* remaining character are padded with null bytes. If strlen >= cnt, no +* terminating null byte is added. 2-byte MBCS characters are handled +* correctly. +* +*Entry: +* unsigned char *dst = destination for copy +* unsigned char *src = source for copy +* int cnt = number of characters to copy +* +*Exit: +* returns dst = destination of copy +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +#pragma warning(suppress:6101) // Returning uninitialized memory '*dst'. A successful path through the function does not set the named _Out_ parameter. +extern "C" unsigned char * __cdecl _mbsncpy_l( + unsigned char *dst, + const unsigned char *src, + size_t cnt, + _locale_t plocinfo + ) +{ + unsigned char *start = dst; + _LocaleUpdate _loc_update(plocinfo); + + /* validation section */ + _VALIDATE_RETURN(dst != nullptr || cnt == 0, EINVAL, nullptr); + _VALIDATE_RETURN(src != nullptr || cnt == 0, EINVAL, nullptr); + + _BEGIN_SECURE_CRT_DEPRECATION_DISABLE + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) +#pragma warning(suppress:__WARNING_BANNED_API_USAGE) + return (unsigned char *)strncpy((char *)dst, (const char *)src, cnt); + _END_SECURE_CRT_DEPRECATION_DISABLE + + while (cnt) { + + cnt--; + if ( _ismbblead_l(*src, _loc_update.GetLocaleT()) ) { + *dst++ = *src++; + if ((*dst++ = *src++) == '\0') { + dst[-2] = '\0'; + break; + } + } + else + if ((*dst++ = *src++) == '\0') + break; + + } + + /* pad with nulls as needed */ + + while (cnt--) + *dst++ = '\0'; + +#pragma warning(suppress:__WARNING_POSTCONDITION_NULLTERMINATION_VIOLATION) // 26036 REVIEW annotation mistake? + return start; +} +extern "C" unsigned char * (__cdecl _mbsncpy)( + unsigned char *dst, + const unsigned char *src, + size_t cnt + ) +{ + _BEGIN_SECURE_CRT_DEPRECATION_DISABLE + return _mbsncpy_l(dst, src, cnt, nullptr); + _END_SECURE_CRT_DEPRECATION_DISABLE +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy_s.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy_s.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3886c9672739834efe30af139ecd7dff8dbfe36a --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy_s.cpp @@ -0,0 +1,16 @@ +/*** +*mbsncpy_s.c - Copy one string to another, n chars only (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Copy one string to another, n chars only (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include + +_REDIRECT_TO_L_VERSION_4(errno_t, _mbsncpy_s, unsigned char *, size_t, const unsigned char *, size_t) diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy_s.inl b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy_s.inl new file mode 100644 index 0000000000000000000000000000000000000000..2d422a7c4c6207cc4578e07660c142f8a5c6cbc9 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy_s.inl @@ -0,0 +1,208 @@ +/*** +*mbsncpy_s.inl - general implementation of _mbsncpy_s and _mbsnbcpy_s +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* This file contains the general algorithm for _mbsncpy_s and _mbsnbcpy_s. +* +* _COUNT_IN_BYTES defined to 1 implements _mbsnbcpy_s +* _COUNT_IN_BYTES defined to 0 implements _mbsncpy_s +* +****/ + +errno_t __cdecl _FUNC_NAME(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _COUNT, _LOCALE_ARG_DECL) +{ + unsigned char *p; + size_t available; + BOOL fFoundInvalidMBC; + BOOL fIsLeadPrefix; + + fFoundInvalidMBC = FALSE; + + if (_COUNT == 0 && _Dst == nullptr && _SizeInBytes == 0) + { + /* this case is allowed; nothing to do */ + _RETURN_NO_ERROR; + } + + /* validation section */ + _VALIDATE_STRING(_Dst, _SizeInBytes); + if (_COUNT == 0) + { + /* notice that the source string pointer can be NULL in this case */ +#pragma prefast(suppress:__WARNING_POTENTIAL_BUFFER_OVERFLOW_HIGH_PRIORITY) /* 26015 */ + _RESET_STRING(_Dst, _SizeInBytes); + _RETURN_NO_ERROR; + } + _VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes); + + _LOCALE_UPDATE; + if (_LOCALE_SHORTCUT_TEST) + { + return strncpy_s((char *)_Dst, _SizeInBytes, (const char *)_Src, _COUNT); + } + + p = _Dst; + available = _SizeInBytes; + if (_COUNT == _TRUNCATE) + { + while ((*p++ = *_Src++) != 0 && --available > 0) + { + } + + /* + * loop terminates with either: + * - src, p pointing 1 byte past null, avail includes the null + * - available == 0, p points 1 past end of dst buffer + */ + } + else + { +#if _COUNT_IN_BYTES + while ((*p++ = *_Src++) != 0 && --available > 0 && --_COUNT > 0) + { + } + + /* + * loop terminates with either: + * - p points 1 byte past null, avail includes null, count includes null + * - available == 0, p points 1 past end of dst buffer (inaccessible) + * - count == 0, p points 1 past last written byte, space available in dst buffer + * + * always p[-1] is written. + * sometimes p[-1] is null. + */ +#else /* _COUNT_IN_BYTES */ + + /* at this point, avail count be 1. */ + + /* Need to track lead-byte context in order to track character count. */ + do + { + if (_ISMBBLEAD(*_Src)) + { + if (_Src[1] == 0) + { + /* + * Invalid MBC, write null to dst string, we are finished + * copying. We know that available is >= 1, so there is + * room for the null termination. If we decrement available + * then we will incorrectly report BUFFER_TOO_SMALL. + */ + + *p++ = 0; + fFoundInvalidMBC = TRUE; + break; + } + if (available <= 2) + { + /* not enough space for a dbc and null */ + available = 0; + break; + } + *p++ = *_Src++; + *p++ = *_Src++; + available -= 2; + } + else + { + if ((*p++ = *_Src++) == 0 || --available == 0) + { + break; + } + } + } + while (--_COUNT > 0); +#endif /* _COUNT_IN_BYTES */ + + /* If count == 0 then at least one byte was copied and available is still > 0 */ + if (_COUNT == 0) + { + *p++ = 0; + /* Note that available is not decremented here. */ + } + } + + if (available == 0) + { +#if _COUNT_IN_BYTES + /* + * For COUNT_IN_BYTES, the above loop copied at least one byte so src,p point + * past a written byte. + */ + + if (*_Src == 0 || _COUNT == 1) + { + fIsLeadPrefix = FALSE; + _ISMBBLEADPREFIX(fIsLeadPrefix, _Dst, &p[-1]); + if (fIsLeadPrefix) + { + /* the source string ended with a lead byte: we remove it */ + p[-1] = 0; + _RETURN_MBCS_ERROR; + } + } +#endif /* _COUNT_IN_BYTES */ + + if (_COUNT == _TRUNCATE) + { + if (fFoundInvalidMBC) + { + _SET_MBCS_ERROR; + } + + if (_SizeInBytes > 1) + { + fIsLeadPrefix = FALSE; + /* Check if 2nd to last copied byte acted as a lead. + * Do not set mbcs error because we are truncating. + */ + _ISMBBLEADPREFIX(fIsLeadPrefix,_Dst,&_Dst[_SizeInBytes - 2]); + if (fIsLeadPrefix) + { + _Dst[_SizeInBytes - 2] = 0; + _FILL_BYTE(_Dst[_SizeInBytes - 1]); + _RETURN_TRUNCATE; + } + } + + _Dst[_SizeInBytes - 1] = 0; + _RETURN_TRUNCATE; + } + _RESET_STRING(_Dst, _SizeInBytes); + _RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); + } + +#if _COUNT_IN_BYTES + /* + * COUNT_IN_BYTES copy loop doesn't track lead-byte context, so can't detect + * invalid mbc. Detect them here. + + * available < _SizeInBytes means that at least one byte was copied so p is >= &dstBuffer[1] + */ + + if ((p - _Dst) >= 2) + { + _ISMBBLEADPREFIX(fIsLeadPrefix, _Dst,&p[-2]); + if (fIsLeadPrefix) + { + /* the source string ended with a lead byte: we remove it */ + p[-2] = 0; + available++; + fFoundInvalidMBC = TRUE; + } + } +#endif /* _COUNT_IN_BYTES */ + + _FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); + + if (fFoundInvalidMBC) + { + _RETURN_MBCS_ERROR; + } + +#pragma warning(suppress:__WARNING_POSTCONDITION_NULLTERMINATION_VIOLATION) /* 26036 REVIEW TODO test _mbsnbcpy_s_l */ + _RETURN_NO_ERROR; +} + diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy_s_l.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy_s_l.cpp new file mode 100644 index 0000000000000000000000000000000000000000..553f19484d4d043d9d4f214c477d810c6a86e246 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsncpy_s_l.cpp @@ -0,0 +1,21 @@ +/*** +*mbsncpy_s_l.c - Copy one string to another, n chars only (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Copy one string to another, n chars only (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +#define _FUNC_NAME _mbsncpy_s_l +#define _COUNT _CountInChars +#define _COUNT_IN_BYTES 0 + +#include "mbsncpy_s.inl" diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnextc.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnextc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6c6ff65001c08f8f40580945b181042c5ee99463 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnextc.cpp @@ -0,0 +1,64 @@ +/*** +*mbsnextc.c - Get the next character in an MBCS string. +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* To return the value of the next character in an MBCS string. +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 + +/*** +*_mbsnextc: Returns the next character in a string. +* +*Purpose: +* To return the value of the next character in an MBCS string. +* Does not advance pointer to the next character. +* +*Entry: +* unsigned char *s = string +* +*Exit: +* unsigned int next = next character. +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" unsigned int __cdecl _mbsnextc_l( + const unsigned char *s, + _locale_t plocinfo + ) +{ + unsigned int next = 0; + _LocaleUpdate _loc_update(plocinfo); + + /* validation section */ + _VALIDATE_RETURN(s != nullptr, EINVAL, 0); + + /* don't skip forward 2 if the leadbyte is followed by EOS (dud string) + also don't assert as we are too low-level + */ + if ( _ismbblead_l(*s, _loc_update.GetLocaleT()) && s[1]!='\0') + next = ((unsigned int) *s++) << 8; + + next += (unsigned int) *s; + + return(next); +} +extern "C" unsigned int (__cdecl _mbsnextc)( + const unsigned char *s + ) +{ + return _mbsnextc_l(s, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnicmp.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnicmp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d6b954be44f983ced30efa93e65dd9fe9a12c0bb --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnicmp.cpp @@ -0,0 +1,115 @@ +/*** +*mbsnicmp.c - Compare n characters of strings, ignoring case (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Compare n characters of strings, ignoring case (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +/*** +* _mbsnicmp - Compare n characters of strings, ignoring case (MBCS) +* +*Purpose: +* Compares up to n charcters of two strings for ordinal order. +* Strings are compared on a character basis, not a byte basis. +* Case of characters is not considered. +* +*Entry: +* unsigned char *s1, *s2 = strings to compare +* size_t n = maximum number of characters to compare +* +*Exit: +* Returns <0 if s1 < s2 +* Returns 0 if s1 == s2 +* Returns >0 if s1 > s2 +* Returns _NLSCMPERROR is something went wrong +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" int __cdecl _mbsnicmp_l( + const unsigned char *s1, + const unsigned char *s2, + size_t n, + _locale_t plocinfo + ) +{ + unsigned short c1, c2; + + if (n==0) + return(0); + + _LocaleUpdate _loc_update(plocinfo); + 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 (*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 (*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()); + + if (c1 != c2) + return( (c1 > c2) ? 1 : -1 ); + + if (c1 == 0) + return(0); + } + + return(0); +} + +extern "C" int (__cdecl _mbsnicmp)( + const unsigned char *s1, + const unsigned char *s2, + size_t n + ) +{ + return _mbsnicmp_l(s1, s2, n, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnicol.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnicol.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd36d49c5dbd0629910a3524cdf18e189bc8d3be --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnicol.cpp @@ -0,0 +1,93 @@ +/*** +*mbsnicol.c - Collate n characters of strings, ignoring case (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Collate n characters of strings, ignoring case (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include + + +/*** +* _mbsnicoll - Collate n characters of strings, ignoring case (MBCS) +* +*Purpose: +* Collates up to n charcters of two strings for lexical order. +* Strings are collated on a character basis, not a byte basis. +* Case of characters is not considered. +* +*Entry: +* unsigned char *s1, *s2 = strings to collate +* size_t n = maximum number of characters to collate +* +*Exit: +* Returns <0 if s1 < s2 +* Returns 0 if s1 == s2 +* Returns >0 if s1 > s2 +* Returns _NLSCMPERROR is something went wrong +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" int __cdecl _mbsnicoll_l( + const unsigned char *s1, + const unsigned char *s2, + size_t n, + _locale_t plocinfo + ) +{ + int ret; + size_t bcnt1, bcnt2; + _LocaleUpdate _loc_update(plocinfo); + + if (n == 0) + return 0; + + /* validation section */ + _VALIDATE_RETURN(s1 != nullptr, EINVAL, _NLSCMPERROR); + _VALIDATE_RETURN(s2 != nullptr, EINVAL, _NLSCMPERROR); + _VALIDATE_RETURN(n <= INT_MAX, EINVAL, _NLSCMPERROR); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return _strnicoll_l((const char *)s1, (const char *)s2, n, plocinfo); + + bcnt1 = _mbsnbcnt_l(s1, n, _loc_update.GetLocaleT()); + bcnt2 = _mbsnbcnt_l(s2, n, _loc_update.GetLocaleT()); + + if ( 0 == (ret = __acrt_CompareStringA( + _loc_update.GetLocaleT(), + _loc_update.GetLocaleT()->mbcinfo->mblocalename, + SORT_STRINGSORT | NORM_IGNORECASE, + (const char *)s1, + (int)bcnt1, + (char *)s2, + (int)bcnt2, + _loc_update.GetLocaleT()->mbcinfo->mbcodepage )) ) + { + errno = EINVAL; + return _NLSCMPERROR; + } + + return ret - 2; + +} + +extern "C" int (__cdecl _mbsnicoll)( + const unsigned char *s1, + const unsigned char *s2, + size_t n + ) +{ + return _mbsnicoll_l(s1, s2, n, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsninc.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsninc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f1ba7adb7017e3d7cc3b2cb6006582a2cbb170e3 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsninc.cpp @@ -0,0 +1,56 @@ +/*** +*mbsninc.c - Increment MBCS string pointer by specified char count. +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Increment MBCS string pointer by specified char count. +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +/*** +*_mbsninc - Increment MBCS string pointer by specified char count. +* +*Purpose: +* Increment the supplied string pointer by the specified number +* of characters. MBCS characters are handled correctly. +* +*Entry: +* const unsigned char *string = pointer to string +* unsigned int ccnt = number of char to advance the pointer +* +*Exit: +* Returns pointer after advancing it. +* Returns pointer to end of string if string is not ccnt chars long. +* Returns nullptr is supplied pointer is nullptr. +* +*Exceptions: +* +*******************************************************************************/ + +extern "C" unsigned char * __cdecl _mbsninc_l( + const unsigned char *string, + size_t ccnt, + _locale_t plocinfo + ) +{ + if (string == nullptr) + return nullptr; + + return const_cast(string) + (unsigned int)_mbsnbcnt_l(string, ccnt, plocinfo); +} + +extern "C" unsigned char * (__cdecl _mbsninc)( + const unsigned char *string, + size_t ccnt + ) +{ + return _mbsninc_l(string, ccnt, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2d5c258252fee1de6832c6aa91e5ca3e85c5e7e8 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset.cpp @@ -0,0 +1,143 @@ +/*** +*mbsnset.c - Sets first n charcaters of string to given character (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Sets first n charcaters of string to given character (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + + +/*** +* _mbsnset - Sets first n charcaters of string to given character (MBCS) +* +*Purpose: +* Sets the first n characters of string to the supplied +* character value. If the length of string is less than n, +* the length of string is used in place of n. Handles +* MBCS chars correctly. +* +* There are several factors that make this routine complicated: +* (1) The fill value may be 1 or 2 bytes long. +* (2) The fill operation may end by hitting the count value +* or by hitting the end of the string. +* (3) A null terminating char is NOT placed at the end of +* the string. +* +* Cases to be careful of (both of these can occur at once): +* (1) Leaving an "orphaned" trail byte in the string (e.g., +* overwriting a lead byte but not the corresponding trail byte). +* (2) Writing only the 1st byte of a 2-byte fill value because the +* end of string was encountered. +* +*Entry: +* unsigned char *string = string to modify +* unsigned int val = value to fill string with +* size_t count = count of characters to fill +* +* +*Exit: +* Returns string = now filled with char val +* +*Uses: +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" unsigned char * __cdecl _mbsnset_l( + unsigned char *string, + unsigned int val, + size_t count, + _locale_t plocinfo + ) +{ + unsigned char *start = string; + unsigned int leadbyte = 0; + unsigned char highval, lowval; + _LocaleUpdate _loc_update(plocinfo); + + /* validation section */ + _VALIDATE_RETURN(string != nullptr || count == 0, EINVAL, nullptr); + + /* + * leadbyte flag indicates if the last byte we overwrote was + * a lead byte or not. + */ +_BEGIN_SECURE_CRT_DEPRECATION_DISABLE + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return (unsigned char *)_strnset((char *)string, val, count); +_END_SECURE_CRT_DEPRECATION_DISABLE + + highval = static_cast(val >> 8); + if (highval != 0) + { + + /* double byte value */ + + lowval = (unsigned char)(val & 0x00ff); + + if(lowval=='\0') + { + _ASSERTE(("invalid MBCS pair passed to mbsnset",0)); + + /* Ideally we would return nullptr here and signal an error + condition. But since this function has no other + error modes, there would be a good chance of crashing + the caller. So instead we fill the string with spaces + to ensure that no information leaks through + unexpectedly. Anyway, we do set errno to EINVAL. + */ + errno = EINVAL; + lowval=highval=' '; + } + + while (count-- && *string) { + leadbyte = _ismbbtruelead_l(leadbyte, *string, _loc_update.GetLocaleT()); + *string++ = highval; + + if (*string) { + leadbyte = _ismbbtruelead_l(leadbyte, *string, _loc_update.GetLocaleT()); + *string++ = lowval; + } + else + /* overwrite orphaned highval byte */ + *(string-1) = ' '; + } + } + + else { + /* single byte value */ + + while (count-- && *string) { + leadbyte = _ismbbtruelead_l(leadbyte, *string, _loc_update.GetLocaleT()); + *string++ = (unsigned char)val; + } + } + + /* overwrite orphaned trailing byte, if necessary */ + if(leadbyte && *string) + *string = ' '; + + return( start ); +} + +unsigned char * (__cdecl _mbsnset)( + unsigned char *string, + unsigned int val, + size_t count + ) +{ +_BEGIN_SECURE_CRT_DEPRECATION_DISABLE + return _mbsnset_l(string, val, count, nullptr); +_END_SECURE_CRT_DEPRECATION_DISABLE +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset_s.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset_s.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dfc6dce091208c070c2b42e964c8e507b1105750 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset_s.cpp @@ -0,0 +1,17 @@ +/*** +*mbsnset_s.c - Sets first n characters of string to given character (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Sets first n characters of string to given character (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +_REDIRECT_TO_L_VERSION_4(errno_t, _mbsnset_s, unsigned char*, size_t, unsigned int, size_t) diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset_s.inl b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset_s.inl new file mode 100644 index 0000000000000000000000000000000000000000..0f27cebf43f96828c5a711feb6f7b976513acf4f --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset_s.inl @@ -0,0 +1,132 @@ +/*** +*mbsnset_s.inl - general implementation of _mbsnset_s and _mbsnbset_s +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* This file contains the general algorithm for _mbsnset_s and _mbsnbset_s. +* +****/ + +errno_t __cdecl _FUNC_NAME(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, size_t _COUNT, _LOCALE_ARG_DECL) +{ + int mbcs_error = 0; + unsigned char *p; + size_t available; + unsigned char highval, lowval; + int mblead = 0; + + /* validation section */ + if (_COUNT == 0 && _Dst == nullptr && _SizeInBytes == 0) + { + /* this case is allowed; nothing to do */ + _RETURN_NO_ERROR; + } + _VALIDATE_STRING(_Dst, _SizeInBytes); + + _LOCALE_UPDATE; + if (_LOCALE_SHORTCUT_TEST) + { + return _strnset_s((char *)_Dst, _SizeInBytes, (int)_Value, _COUNT); + } + + p = _Dst; + available = _SizeInBytes; + highval = (unsigned char)(_Value >> 8); + lowval = (unsigned char)(_Value & 0x00ff); + + /* ensure _Value is a valid mbchar */ + if ((highval != 0 && (lowval == 0 || !_ISMBBLEAD(highval))) || + (highval == 0 && _ISMBBLEAD(lowval))) + { + _RESET_STRING(_Dst, _SizeInBytes); + _RETURN_MBCS_ERROR; + } + + if (highval != 0) + { +#if _COUNT_IN_BYTES + /* if _COUNT is odd, make it even subtracting 1 */ + /* divide _COUNT by 2 to have a count in chars instead of bytes */ + if ((_COUNT & 1) == 1) + { + --_COUNT; + mbcs_error = 1; + } + _COUNT = _COUNT / 2; +#endif /* _COUNT_IN_BYTES */ + while (*p != 0 && _COUNT > 0 && --available > 0) + { + if (p[1] == 0) + { + /* do not orphan leadbyte */ + *p = 0; + ++available; + mbcs_error = 1; + break; + } + /* track the mblead status in the original string */ + mblead = mblead ? 0 : _ISMBBLEAD(*p); + *p++ = highval; + if (--available == 0) + { + break; + } + mblead = mblead ? 0 : _ISMBBLEAD(*p); + *p++ = lowval; + --_COUNT; + } + } + else + { + while (*p != 0 && _COUNT > 0 && --available > 0) + { + /* track the mblead status in the original string */ + mblead = mblead ? 0 : _ISMBBLEAD(*p); + *p++ = lowval; + --_COUNT; + } + } + + /* if the last written byte overlapps a leadbyte, + * copy a space over the corresponding trailbyte */ + if (_COUNT == 0 && mblead && *p != 0 && --available > 0) + { + mbcs_error = 1; + if (p[1] == 0) + { + /* special case: if the space would be followed by 0, just put a 0 */ + *p = 0; + ++available; + } + else + { + *p++ = ' '; + } + } + + if (_COUNT == 0) + { + /* ensure the string is null-terminated */ + while (*p != 0 && --available > 0) + { + ++p; + } + } + + if (available == 0) + { + _RESET_STRING(_Dst, _SizeInBytes); + _RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes); + } + _FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); + if (mbcs_error) + { + _RETURN_MBCS_ERROR; + } + else + { + _RETURN_NO_ERROR; + } +} + diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset_s_l.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset_s_l.cpp new file mode 100644 index 0000000000000000000000000000000000000000..00fc5f3cb26ed6b866bf9809bcc905f56cca1e67 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsnset_s_l.cpp @@ -0,0 +1,21 @@ +/*** +*mbsnset_s_l.c - Sets first n characters of string to given character (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Sets first n characters of string to given character (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +#define _FUNC_NAME _mbsnset_s_l +#define _COUNT _CountInChars +#define _COUNT_IN_BYTES 0 + +#include "mbsnset_s.inl" diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbspbrk.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbspbrk.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa67994eaa502f8fceb5ba8431626d9448e831fe --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbspbrk.cpp @@ -0,0 +1,16 @@ +/*** +*mbspbrk.c - Find first string char in charset, pointer return (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Find first string char in charset, pointer return (MBCS) +* Shares common source file with mbscspn.c. +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#define _RETURN_PTR +#include "mbscspn.cpp" diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsrchr.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsrchr.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c1467cadd5891c8fc42ba89be02373ec519578ed --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsrchr.cpp @@ -0,0 +1,83 @@ +/*** +*mbsrchr.c - Search for last occurence of character (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Search for last occurence of character (MBCS) +* +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include + +#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 + +/*** +* _mbsrchr - Search for last occurence of character (MBCS) +* +*Purpose: +* Find the last occurrence of the specified character in +* the supplied string. Handles MBCS chars/strings correctly. +* +*Entry: +* unsigned char *str = string to search in +* unsigned int c = character to search for +* +*Exit: +* returns pointer to last occurrence of c in str +* returns nullptr if c not found +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" _CONST_RETURN unsigned char * __cdecl _mbsrchr_l( + const unsigned char *str, + unsigned int c, + _locale_t plocinfo + ) +{ + char *r = nullptr; + unsigned int cc; + _LocaleUpdate _loc_update(plocinfo); + + /* validation section */ + _VALIDATE_RETURN(str != nullptr, EINVAL, 0); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return (_CONST_RETURN unsigned char *)strrchr((const char *)str, c); + + do { + cc = *str; + if ( _ismbblead_l(cc, _loc_update.GetLocaleT()) ) { + if(*++str) { + if (c == ((cc<<8)|*str)) + r = (char *)str - 1; + } + else if(!r) + /* return pointer to '\0' */ + r = (char *)str; + } + else if (c == cc) + r = (char *)str; + } + while (*str++); + + return((_CONST_RETURN unsigned char *)r); +} + +extern "C" _CONST_RETURN unsigned char * (__cdecl _mbsrchr)( + const unsigned char *str, + unsigned int c + ) +{ + return _mbsrchr_l(str, c, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsrev.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsrev.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ed738783a712211e0982b7252c6d6e1b2e9b4d38 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsrev.cpp @@ -0,0 +1,108 @@ +/*** +*mbsrev.c - Reverse a string in place (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Reverse a string in place (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + + +/*** +* _mbsrev - Reverse a string in place (MBCS) +* +*Purpose: +* Reverses the order of characters in the string. The terminating +* null character remains in place. The order of MBCS characters +* is not changed. +* +*Entry: +* unsigned char *string = string to reverse +* +*Exit: +* returns string - now with reversed characters +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" unsigned char * __cdecl _mbsrev_l( + unsigned char *string, + _locale_t plocinfo + ) +{ + unsigned char *start = string; + unsigned char *left = string; + unsigned char c; + _LocaleUpdate _loc_update(plocinfo); + + /* validation section */ + _VALIDATE_RETURN(string != nullptr, EINVAL, nullptr); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return (unsigned char *)_strrev((char *)string); + + + /* first go through and reverse the bytes in MBCS chars */ + while ( *string ) { + if ( _ismbblead_l(*string++, _loc_update.GetLocaleT()) ) { + if ( *string ) { + c = *string; + *string = *(string - 1); + *(string - 1) = c; + string++; + } + else + { + /* second byte is EOS + There is nothing really satisfying to do here. We have a string + that ends in leadbyte,'\0'. Reversing this would lead to the leadbyte + becoming falsely attached to the character before it: + (XL0 -> LX0, X has suddenly become a trailbyte) + + So what we choose to do is assert and purge the dud byte from within the + string. + */ + errno = EINVAL; + _ASSERTE(("Bad MBCS string passed into _mbsrev",0)); + + /* String has at least moved once already, so this is safe */ + _ASSERTE(string>start); + + /* move back one to point at the dud leadbyte */ + --string; + + /* now truncate the string one byte earlier */ + *string='\0'; + + break; + } + } + } + + /* now reverse the whole string */ + string--; + while ( left < string ) { + c = *left; + *left++ = *string; + *string-- = c; + } + + return ( start ); +} + +extern "C" unsigned char * (__cdecl _mbsrev)( + unsigned char *string + ) +{ + return _mbsrev_l(string, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsset.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsset.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5230f3a8aeb0a80b73636c8a5caa368b0e7111e2 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsset.cpp @@ -0,0 +1,110 @@ +/*** +*mbsset.c - Sets all charcaters of string to given character (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Sets all charcaters of string to given character (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include + +/*** +* mbsset - Sets all charcaters of string to given character (MBCS) +* +*Purpose: +* Sets all of characters in string (except the terminating '/0' +* character) equal to the supplied character. Handles MBCS +* chars correctly. +* +*Entry: +* unsigned char *string = string to modify +* unsigned int val = value to fill string with +* +*Exit: +* returns string = now filled with the specified char +* +*Uses: +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" unsigned char * __cdecl _mbsset_l( + unsigned char *string, + unsigned int val, + _locale_t plocinfo + ) +{ + unsigned char *start = string; + unsigned char highval, lowval; + _LocaleUpdate _loc_update(plocinfo); + + /* validation section */ + _VALIDATE_RETURN(string != nullptr, EINVAL, nullptr); + +_BEGIN_SECURE_CRT_DEPRECATION_DISABLE + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return (unsigned char *)_strset((char *)string, val); +_END_SECURE_CRT_DEPRECATION_DISABLE + + highval = static_cast(val >> 8); + if (highval != 0) + { + /* 2-byte value */ + + lowval = (unsigned char)(val & 0x00ff); + + if(lowval=='\0') + { + _ASSERTE(("invalid MBCS pair passed to mbsset",0)); + + /* Ideally we would return nullptr here and signal an error + condition. But since this function has no other + error modes, there would be a good chance of crashing + the caller. So instead we fill the string with spaces + to ensure that no information leaks through + unexpectedly. Anyway, we do set errno to EINVAL. + */ + errno = EINVAL; + lowval=highval=' '; + } + + while (*string) { + + *string++ = highval; + if (*string) + *string++ = lowval; + else + /* don't orphan lead byte */ + string[-1] = ' '; + } + + } + + else { + /* single byte value */ + + while (*string) + *string++ = (unsigned char)val; + } + + return(start); +} + +extern "C" unsigned char * (__cdecl _mbsset)( + unsigned char *string, + unsigned int val + ) +{ +_BEGIN_SECURE_CRT_DEPRECATION_DISABLE + return _mbsset_l(string, val, nullptr); +_END_SECURE_CRT_DEPRECATION_DISABLE +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsset_s.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsset_s.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8968d11496eb4467c7bcc6394381aeda73cc72b --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsset_s.cpp @@ -0,0 +1,16 @@ +/*** +*mbsset_s.c - Sets all charcaters of string to given character (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Sets all charcaters of string to given character (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include + +_REDIRECT_TO_L_VERSION_3(errno_t, _mbsset_s, unsigned char*, size_t, unsigned int) diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsset_s_l.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsset_s_l.cpp new file mode 100644 index 0000000000000000000000000000000000000000..01e43e320d811cd174b643238e40ea7a3e9d9073 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsset_s_l.cpp @@ -0,0 +1,89 @@ +/*** +*mbsset_s_l.c - Sets all charcaters of string to given character (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Sets all charcaters of string to given character (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include + +errno_t __cdecl _mbsset_s_l(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, _LOCALE_ARG_DECL) +{ + int mbcs_error = 0; + unsigned char *p; + size_t available; + unsigned char highval, lowval; + + /* validation section */ + _VALIDATE_STRING(_Dst, _SizeInBytes); + + _LOCALE_UPDATE; + if (_LOCALE_SHORTCUT_TEST) + { + return _strset_s((char *)_Dst, _SizeInBytes, (int)_Value); + } + + p = _Dst; + available = _SizeInBytes; + highval = (unsigned char)(_Value >> 8); + lowval = (unsigned char)(_Value & 0x00ff); + + /* ensure _Value is a valid mbchar */ + if ((highval != 0 && (lowval == 0 || !_ISMBBLEAD(highval))) || + (highval == 0 && _ISMBBLEAD(lowval))) + { + _RESET_STRING(_Dst, _SizeInBytes); + _RETURN_MBCS_ERROR; + } + + if (highval != 0) + { + while (*p != 0 && --available > 0) + { + if (p[1] == 0) + { + /* do not orphan leadbyte */ + *p = 0; + ++available; + mbcs_error = 1; + break; + } + *p++ = highval; + if (--available == 0) + { + break; + } + *p++ = lowval; + } + } + else + { + while (*p != 0 && --available > 0) + { + *p++ = lowval; + } + } + + if (available == 0) + { + _RESET_STRING(_Dst, _SizeInBytes); + _RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes); + } + _FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); + + if (mbcs_error) + { + _RETURN_MBCS_ERROR; + } + else + { + _RETURN_NO_ERROR; + } +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsspn.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsspn.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f685cb2f6feaf4ccc15ae0ff5d3ec99d90e26410 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsspn.cpp @@ -0,0 +1,130 @@ +/*** +*mbsspn.c - Search for init substring of chars from control string (MBCS). +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Search for init substring of chars from control string (MBCS). +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include +#include + +/*** +*ifndef _RETURN_PTR +* _mbsspn - Find first string char not in charset (MBCS) +*else +* _mbsspnp - Find first string char not in charset, return pointer (MBCS) +*endif +* +*Purpose: +* Returns maximum leading segment of string consisting solely +* of characters from charset. Handles MBCS characters correctly. +* +*Entry: +* unsigned char *string = string to search in +* unsigned char *charset = set of characters to scan over +* +*Exit: +* +*ifndef _RETURN_PTR +* Returns index of first char in string not in control. +* Returns 0, if string begins with a character not in charset. +*else +* Returns pointer to first character not in charset. +* Returns nullptr if string consists entirely of characters from charset. +*endif +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +#ifndef _RETURN_PTR +extern "C" size_t __cdecl _mbsspn_l +#else /* _RETURN_PTR */ +extern "C" unsigned char * __cdecl _mbsspnp_l +#endif /* _RETURN_PTR */ + ( + const unsigned char *string, + const unsigned char *charset, + _locale_t plocinfo + ) +{ + unsigned char *p, *q; + _LocaleUpdate _loc_update(plocinfo); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) +#ifndef _RETURN_PTR + return strspn((const char *)string, (const char *)charset); +#else /* _RETURN_PTR */ + { + size_t retval; + retval = strspn((const char *)string, (const char *)charset); + return (unsigned char *)(*(string + retval) ? string + retval : nullptr); + } +#endif /* _RETURN_PTR */ + + /* validation section */ +#ifndef _RETURN_PTR + _VALIDATE_RETURN(string != nullptr, EINVAL, 0); + _VALIDATE_RETURN(charset != nullptr, EINVAL, 0); +#else /* _RETURN_PTR */ + _VALIDATE_RETURN(string != nullptr, EINVAL, nullptr); + _VALIDATE_RETURN(charset != nullptr, EINVAL, nullptr); +#endif /* _RETURN_PTR */ + + /* loop through the string to be inspected */ + for (q = (unsigned char *)string; *q; q++) { + + /* loop through the charset */ + for (p = (unsigned char *)charset; *p; p++) { + if ( _ismbblead_l(*p, _loc_update.GetLocaleT()) ) { + if (((*p == *q) && (p[1] == q[1])) || p[1] == '\0') + break; + p++; + } + else + if (*p == *q) + break; + } + + if (*p == '\0') /* end of charset? */ + break; /* yes, no match on this char */ + + if ( _ismbblead_l(*q, _loc_update.GetLocaleT()) ) + if (*++q == '\0') + break; + } + +#ifndef _RETURN_PTR + return((size_t) (q - string)); /* index */ +#else /* _RETURN_PTR */ + return((*q) ? q : nullptr); /* pointer */ +#endif /* _RETURN_PTR */ + +} + +#ifndef _RETURN_PTR +extern "C" size_t (__cdecl _mbsspn) +#else /* _RETURN_PTR */ +extern "C" unsigned char * (__cdecl _mbsspnp) +#endif /* _RETURN_PTR */ + ( + const unsigned char *string, + const unsigned char *charset + ) +{ +#ifndef _RETURN_PTR + return _mbsspn_l(string, charset, nullptr); +#else /* _RETURN_PTR */ + return _mbsspnp_l(string, charset, nullptr); +#endif /* _RETURN_PTR */ +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsspnp.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsspnp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c6401bc12845c5b5ca28171c9a3bbeccf687910 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsspnp.cpp @@ -0,0 +1,16 @@ +/*** +*mbsspnp.c - Find first string char in charset, pointer return (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Returns maximum leading segment of string consisting solely +* of characters from charset. Handles MBCS characters correctly. +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#define _RETURN_PTR +#include "mbsspn.cpp" diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsstr.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsstr.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7344a49238d922b13a1e0bbec6e3c5f3dfbc7530 --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbsstr.cpp @@ -0,0 +1,101 @@ +/*** +* mbsstr.c - Search for one MBCS string inside another +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Search for one MBCS string inside another +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include +#include + +/*** +* _mbsstr - Search for one MBCS string inside another +* +*Purpose: +* Find the first occurrence of str2 in str1. +* +*Entry: +* unsigned char *str1 = beginning of string +* unsigned char *str2 = string to search for +* +*Exit: +* Returns a pointer to the first occurrence of str2 in +* str1, or nullptr if str2 does not occur in str1 +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" _CONST_RETURN unsigned char * __cdecl _mbsstr_l( + const unsigned char *str1, + const unsigned char *str2, + _locale_t plocinfo + ) +{ + unsigned char *cp, *s1, *s2, *endp; + _LocaleUpdate _loc_update(plocinfo); + + if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) + return (unsigned char *)strstr((const char *)str1, (const char *)str2); + + /* validation section */ + _VALIDATE_RETURN(str2 != nullptr, EINVAL, 0); + if ( *str2 == '\0') + return (unsigned char *)str1; + _VALIDATE_RETURN(str1 != nullptr, EINVAL, 0); + + cp = (unsigned char *) str1; + endp = (unsigned char *) (str1 + (strlen((const char *)str1) - strlen((const char *)str2))); + + while (*cp && (cp <= endp)) + { + s1 = cp; + s2 = (unsigned char *) str2; + + /* + * MBCS: ok to ++ since doing equality comparison. + * [This depends on MBCS strings being "legal".] + */ + while ( *s1 && *s2 && (*s1 == *s2) ) + s1++, s2++; + + if (!(*s2)) + return(cp); /* success! */ + + /* + * bump pointer to next char + */ + if ( _ismbblead_l(*(cp++), _loc_update.GetLocaleT()) ) + { + /* don't move forward if we have leadbyte, EOS + means dud string was passed in. + Don't assert - too low level + */ + if(*cp!='\0') + { + cp++; + } + } + } + + return(nullptr); + +} + +extern "C" _CONST_RETURN unsigned char * (__cdecl _mbsstr)( + const unsigned char *str1, + const unsigned char *str2 + ) +{ + return _mbsstr_l(str1, str2, nullptr); +} diff --git a/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbstok.cpp b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbstok.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fdab7fee422e81ac6101003cc67688c0dbb2a03d --- /dev/null +++ b/miniMSVC/Windows Kits/10/Source/10.0.26100.0/ucrt/mbstring/mbstok.cpp @@ -0,0 +1,69 @@ +/*** +*mbstok.c - Break string into tokens (MBCS) +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +*Purpose: +* Break string into tokens (MBCS) +* +*******************************************************************************/ +#ifndef _MBCS + #error This file should only be compiled with _MBCS defined +#endif + +#include +#include +#include +#include +#include + +/*** +* _mbstok - Break string into tokens (MBCS) +* +*Purpose: +* strtok considers the string to consist of a sequence of zero or more +* text tokens separated by spans of one or more control chars. the first +* call, with string specified, returns a pointer to the first char of the +* first token, and will write a null char into string immediately +* following the returned token. subsequent calls with zero for the first +* argument (string) will work thru the string until no tokens remain. the +* control string may be different from call to call. when no tokens remain +* in string a nullptr pointer is returned. remember the control chars with a +* bit map, one bit per ascii char. the null char is always a control char. +* +* MBCS chars supported correctly. +* +*Entry: +* char *string = string to break into tokens. +* char *sepset = set of characters to use as seperators +* +*Exit: +* returns pointer to token, or nullptr if no more tokens +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* +*******************************************************************************/ + +extern "C" unsigned char * __cdecl _mbstok_l( + unsigned char* const string, + unsigned char const* const sepset, + _locale_t const locale + ) +{ + return _mbstok_s_l(string, sepset, &__acrt_getptd()->_mbstok_token, locale); +} + +extern "C" unsigned char * __cdecl _mbstok( + unsigned char * string, + const unsigned char * sepset + ) +{ + /* We call the deprecated _mbstok_l (and not _mbstok_s_l) so that we keep one + * single nextoken in the single thread case, i.e. the nextoken declared as static + * inside _mbstok_l + */ + _BEGIN_SECURE_CRT_DEPRECATION_DISABLE + return _mbstok_l(string, sepset, nullptr); + _END_SECURE_CRT_DEPRECATION_DISABLE +}