From cfd60300ced9acd1bfa417d89cfd9f0136ec07e2 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid Date: Wed, 2 Sep 2020 06:25:22 +0300 Subject: [PATCH] Delete multi-byte related functions from PAL (#41611) * Delete multi-byte related functions from PAL In PAL, delete: * `IsDBCSLeadByte`; unimplemented. * `IsDBCSLeadByteEx`; no-op. * `GetCPInfo`; has hardcoded length of 4, and the only usage checks for `length == 1`. * `_mbsinc`; has one usage in ilasm, which is simplified for Unix (after the removal of above). * `_mbsninc`; unused. * `_mbsdec`; usage is inlined as `p--` because `IsDBCSLeadByteEx` is a no-op. * `GetCaseInsensitiveValueA`, handle ANSI cases as Unicode. * `IsTextUnicode`, single usage in ilasm is inlined. * Delete _MBCS, _ismbblead and simplifications * Delete trailing whitespaces from PR file changed --- .../src/dlls/mscordac/mscordac_unixexports.src | 2 - src/coreclr/src/ilasm/asmparse.h | 8 +- src/coreclr/src/ilasm/grammar_after.cpp | 50 +- src/coreclr/src/ilasm/ilasmpch.h | 1 - src/coreclr/src/pal/inc/pal.h | 23 - src/coreclr/src/pal/inc/rt/palrt.h | 6 - src/coreclr/src/pal/inc/rt/safecrt.h | 1678 +------------------- src/coreclr/src/pal/src/CMakeLists.txt | 5 +- src/coreclr/src/pal/src/cruntime/mbstring.cpp | 203 --- src/coreclr/src/pal/src/locale/unicode.cpp | 114 -- src/coreclr/src/pal/src/safecrt/input.inl | 25 - src/coreclr/src/pal/src/safecrt/internal.h | 4 - .../src/pal/src/safecrt/internal_securecrt.h | 26 - src/coreclr/src/pal/src/safecrt/makepath_s.cpp | 2 - src/coreclr/src/pal/src/safecrt/output.inl | 5 - .../src/pal/src/safecrt/safecrt_output_l.cpp | 5 - src/coreclr/src/pal/src/safecrt/splitpath_s.cpp | 2 - src/coreclr/src/pal/src/safecrt/tmakepath_s.inl | 6 +- src/coreclr/src/pal/src/safecrt/tsplitpath_s.inl | 22 +- src/coreclr/src/pal/src/safecrt/wmakepath_s.cpp | 1 - src/coreclr/src/pal/src/safecrt/wsplitpath_s.cpp | 1 - .../pal/tests/palsuite/c_runtime/CMakeLists.txt | 3 - .../palsuite/c_runtime/_mbsdec/CMakeLists.txt | 2 - .../c_runtime/_mbsdec/test1/CMakeLists.txt | 13 - .../palsuite/c_runtime/_mbsdec/test1/test1.cpp | 76 - .../palsuite/c_runtime/_mbsdec/test1/testinfo.dat | 17 - .../palsuite/c_runtime/_mbsinc/CMakeLists.txt | 2 - .../c_runtime/_mbsinc/test1/CMakeLists.txt | 13 - .../palsuite/c_runtime/_mbsinc/test1/test1.cpp | 61 - .../palsuite/c_runtime/_mbsinc/test1/testinfo.dat | 14 - .../palsuite/c_runtime/_mbsninc/CMakeLists.txt | 2 - .../c_runtime/_mbsninc/test1/CMakeLists.txt | 13 - .../palsuite/c_runtime/_mbsninc/test1/test1.cpp | 64 - .../palsuite/c_runtime/_mbsninc/test1/testinfo.dat | 16 - .../pal/tests/palsuite/locale_info/CMakeLists.txt | 3 - .../palsuite/locale_info/GetCPInfo/CMakeLists.txt | 4 - .../locale_info/GetCPInfo/test1/CMakeLists.txt | 13 - .../palsuite/locale_info/GetCPInfo/test1/test1.cpp | 53 - .../locale_info/GetCPInfo/test1/testinfo.dat | 12 - .../locale_info/GetCPInfo/test2/CMakeLists.txt | 13 - .../palsuite/locale_info/GetCPInfo/test2/test2.cpp | 59 - .../locale_info/GetCPInfo/test2/testinfo.dat | 9 - .../locale_info/GetCPInfo/test3/CMakeLists.txt | 13 - .../palsuite/locale_info/GetCPInfo/test3/test3.cpp | 40 - .../locale_info/GetCPInfo/test3/testinfo.dat | 8 - .../locale_info/IsDBCSLeadByte/CMakeLists.txt | 2 - .../IsDBCSLeadByte/test1/CMakeLists.txt | 13 - .../locale_info/IsDBCSLeadByte/test1/test1.cpp | 63 - .../locale_info/IsDBCSLeadByte/test1/testinfo.dat | 12 - .../locale_info/IsDBCSLeadByteEx/CMakeLists.txt | 2 - .../IsDBCSLeadByteEx/test1/CMakeLists.txt | 13 - .../locale_info/IsDBCSLeadByteEx/test1/test1.cpp | 71 - .../IsDBCSLeadByteEx/test1/testinfo.dat | 13 - src/coreclr/src/pal/tests/palsuite/paltestlist.txt | 7 - .../tests/palsuite/paltestlist_to_be_reviewed.txt | 1 - src/coreclr/src/palrt/CMakeLists.txt | 1 - src/coreclr/src/palrt/unicode.cpp | 26 - src/coreclr/src/utilcode/makepath.cpp | 4 - src/coreclr/src/utilcode/splitpath.cpp | 8 - src/coreclr/src/utilcode/sstring.cpp | 72 +- 60 files changed, 102 insertions(+), 2918 deletions(-) delete mode 100644 src/coreclr/src/pal/src/cruntime/mbstring.cpp delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.cpp delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/testinfo.dat delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.cpp delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/testinfo.dat delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.cpp delete mode 100644 src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/testinfo.dat delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.cpp delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/testinfo.dat delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/test2.cpp delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/testinfo.dat delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test3/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test3/test3.cpp delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test3/testinfo.dat delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.cpp delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/testinfo.dat delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/CMakeLists.txt delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.cpp delete mode 100644 src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/testinfo.dat delete mode 100644 src/coreclr/src/palrt/unicode.cpp diff --git a/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src b/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src index 31dd9ea..ddf3625 100644 --- a/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src +++ b/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src @@ -111,7 +111,6 @@ nativeStringResourceTable_mscorrc #FreeLibrary #FileTimeToSystemTime #GetACP -#GetCPInfo #GetCurrentDirectoryW #GetCurrentProcess #GetCurrentProcessId @@ -134,7 +133,6 @@ nativeStringResourceTable_mscorrc #GetTempPathA #GetTempPathW #InitializeCriticalSection -#IsDBCSLeadByte #LeaveCriticalSection #LoadLibraryA #LoadLibraryW diff --git a/src/coreclr/src/ilasm/asmparse.h b/src/coreclr/src/ilasm/asmparse.h index 7585ec6..ef377b5 100644 --- a/src/coreclr/src/ilasm/asmparse.h +++ b/src/coreclr/src/ilasm/asmparse.h @@ -214,7 +214,6 @@ typedef LIFO ARG_NAME_LIST_STACK; /*--------------------------------------------------------------------------*/ typedef char*(*PFN_NEXTCHAR)(char*); -char* nextcharA(__in __nullterminated char* pos); char* nextcharU(__in __nullterminated char* pos); char* nextcharW(__in __nullterminated char* pos); @@ -292,7 +291,7 @@ public: ARG_NAME_LIST_STACK m_ANSFirst; ARG_NAME_LIST_STACK m_ANSLast; PARSING_ENVIRONMENT *penv; - PARSING_ENVIRONMENT_STACK PEStack; + PARSING_ENVIRONMENT_STACK PEStack; private: BinStr* MakeSig(unsigned callConv, BinStr* retType, BinStr* args, int ntyargs = 0); @@ -300,9 +299,8 @@ private: BinStr* MakeTypeArray(CorElementType kind, BinStr* elemType, BinStr* bounds); char* fillBuff(__in_opt __nullterminated char* curPos); // refill the input buffer - DWORD IsItUnicode(CONST LPVOID pBuff, int cb, LPINT lpi); - HANDLE hstdout; - HANDLE hstderr; + HANDLE hstdout; + HANDLE hstderr; private: friend void yyerror(__in __nullterminated const char* str); diff --git a/src/coreclr/src/ilasm/grammar_after.cpp b/src/coreclr/src/ilasm/grammar_after.cpp index dc4c849..ff22f68 100644 --- a/src/coreclr/src/ilasm/grammar_after.cpp +++ b/src/coreclr/src/ilasm/grammar_after.cpp @@ -76,11 +76,6 @@ static Keywords keywords[] = { /********************************************************************************/ /* File encoding-dependent functions */ /*--------------------------------------------------------------------------*/ -char* nextcharA(__in __nullterminated char* pos) -{ - return (*pos > 0) ? ++pos : (char *)_mbsinc((const unsigned char *)pos); -} - char* nextcharU(__in __nullterminated char* pos) { return ++pos; @@ -929,14 +924,10 @@ Its_An_Id: tok = parse_literal(curSym, curPos, FALSE); if(tok == QSTRING) { - // if not ANSI, then string is in UTF-8, - // insert prefix - if(nextchar != nextcharA) - { - yylval.binstr->insertInt8(0xEF); - yylval.binstr->insertInt8(0xBB); - yylval.binstr->insertInt8(0xBF); - } + // insert UTF-8 BOM prefix + yylval.binstr->insertInt8(0xEF); + yylval.binstr->insertInt8(0xBB); + yylval.binstr->insertInt8(0xBF); yylval.binstr->appendInt8(' '); DefineVar(newstr, yylval.binstr); } @@ -1488,12 +1479,6 @@ AsmParse::~AsmParse() } /**************************************************************************/ -DWORD AsmParse::IsItUnicode(CONST LPVOID pBuff, int cb, LPINT lpi) -{ - return IsTextUnicode(pBuff,cb,lpi); -} - -/**************************************************************************/ void AsmParse::CreateEnvironment(ReadStream* stream) { penv = new PARSING_ENVIRONMENT; @@ -1520,19 +1505,21 @@ void AsmParse::ParseFile(ReadStream* stream) char* AsmParse::fillBuff(__in_opt __nullterminated char* pos) { int iPutToBuffer; - int iOptions = IS_TEXT_UNICODE_UNICODE_MASK; - g_uCodePage = CP_ACP; + g_uCodePage = CP_UTF8; iPutToBuffer = (int)penv->in->getAll(&(penv->curPos)); penv->endPos = penv->curPos + iPutToBuffer; if(iPutToBuffer > 128) iPutToBuffer = 128; - if(IsItUnicode(penv->curPos,iPutToBuffer,&iOptions)) + if(iPutToBuffer >= 4 && (penv->curPos[0] & 0xFF) == 0xFF && (penv->curPos[1] & 0xFF) == 0xFE) { - g_uCodePage = CP_UTF8; - if(iOptions & IS_TEXT_UNICODE_SIGNATURE) + // U+FFFE followed by U+0000 is UTF-32 LE, any other value than 0 is a true UTF-16 LE + if((penv->curPos[2] & 0xFF) == 0x00 && (penv->curPos[3] & 0xFF) == 0x00) { - penv->curPos += 2; + error("UTF-32 LE is not supported\n\n"); + return NULL; } + + penv->curPos += 2; // skip signature if(assem->m_fReportProgress) printf("Source file is UNICODE\n\n"); penv->pfn_Sym = SymW; penv->pfn_nextchar = nextcharW; @@ -1542,18 +1529,13 @@ char* AsmParse::fillBuff(__in_opt __nullterminated char* pos) } else { - if(((penv->curPos[0]&0xFF)==0xEF)&&((penv->curPos[1]&0xFF)==0xBB)&&((penv->curPos[2]&0xFF)==0xBF)) + if((penv->curPos[0] & 0xFF) == 0xEF && (penv->curPos[1] & 0xFF) == 0xBB && (penv->curPos[2] & 0xFF) == 0xBF) { - g_uCodePage = CP_UTF8; penv->curPos += 3; - if(assem->m_fReportProgress) printf("Source file is UTF-8\n\n"); - penv->pfn_nextchar = nextcharU; - } - else - { - if(assem->m_fReportProgress) printf("Source file is ANSI\n\n"); - penv->pfn_nextchar = nextcharA; } + + if(assem->m_fReportProgress) printf("Source file is UTF-8\n\n"); + penv->pfn_nextchar = nextcharU; penv->pfn_Sym = SymAU; penv->pfn_NewStrFromToken = NewStrFromTokenAU; penv->pfn_NewStaticStrFromToken = NewStaticStrFromTokenAU; diff --git a/src/coreclr/src/ilasm/ilasmpch.h b/src/coreclr/src/ilasm/ilasmpch.h index d5f8cc2..ece4130 100644 --- a/src/coreclr/src/ilasm/ilasmpch.h +++ b/src/coreclr/src/ilasm/ilasmpch.h @@ -18,7 +18,6 @@ #include "specstrings.h" #include // for strcmp -#include // for _mbsinc #include // for isspace #include "openum.h" // for CEE_* #include // for vararg macros diff --git a/src/coreclr/src/pal/inc/pal.h b/src/coreclr/src/pal/inc/pal.h index bf510a7..133434d 100644 --- a/src/coreclr/src/pal/inc/pal.h +++ b/src/coreclr/src/pal/inc/pal.h @@ -2812,26 +2812,6 @@ typedef struct _cpinfo { BYTE LeadByte[MAX_LEADBYTES]; } CPINFO, *LPCPINFO; -PALIMPORT -BOOL -PALAPI -GetCPInfo( - IN UINT CodePage, - OUT LPCPINFO lpCPInfo); - -PALIMPORT -BOOL -PALAPI -IsDBCSLeadByteEx( - IN UINT CodePage, - IN BYTE TestChar); - -PALIMPORT -BOOL -PALAPI -IsDBCSLeadByte( - IN BYTE TestChar); - #define MB_PRECOMPOSED 0x00000001 #define MB_ERR_INVALID_CHARS 0x00000008 @@ -4021,9 +4001,6 @@ PALIMPORT DLLEXPORT int __cdecl _stricmp(const char *, const char *); PALIMPORT DLLEXPORT int __cdecl vsprintf_s(char *, size_t, const char *, va_list); PALIMPORT char * __cdecl _gcvt_s(char *, int, double, int); PALIMPORT int __cdecl __iscsym(int); -PALIMPORT unsigned char * __cdecl _mbsinc(const unsigned char *); -PALIMPORT unsigned char * __cdecl _mbsninc(const unsigned char *, size_t); -PALIMPORT unsigned char * __cdecl _mbsdec(const unsigned char *, const unsigned char *); PALIMPORT DLLEXPORT int __cdecl _wcsicmp(const WCHAR *, const WCHAR*); PALIMPORT int __cdecl _wcsnicmp(const WCHAR *, const WCHAR *, size_t); PALIMPORT int __cdecl _vsnprintf(char *, size_t, const char *, va_list); diff --git a/src/coreclr/src/pal/inc/rt/palrt.h b/src/coreclr/src/pal/inc/rt/palrt.h index b021277..4f29ea4 100644 --- a/src/coreclr/src/pal/inc/rt/palrt.h +++ b/src/coreclr/src/pal/inc/rt/palrt.h @@ -708,10 +708,6 @@ STDAPI_(LPWSTR) StrCatBuffW(LPWSTR pszDest, LPCWSTR pszSrc, int cchDestBuffSize) #define _SAFECRT_SET_ERRNO 0 #define _SAFECRT_DEFINE_MBS_FUNCTIONS 0 #define _SAFECRT_DEFINE_TCS_MACROS 1 -/* -#define _SAFECRT__ISMBBLEAD(_Character) 0 -#define _SAFECRT__MBSDEC(_String, _Current) (_Current - 1) -*/ #include "safecrt.h" #include "specstrings.h" @@ -876,8 +872,6 @@ typedef HANDLE HWND; #define IS_TEXT_UNICODE_SIGNATURE 0x0008 #define IS_TEXT_UNICODE_UNICODE_MASK 0x000F -BOOL IsTextUnicode(CONST VOID* lpv, int iSize, LPINT lpiResult); - typedef struct _LIST_ENTRY { struct _LIST_ENTRY *Flink; struct _LIST_ENTRY *Blink; diff --git a/src/coreclr/src/pal/inc/rt/safecrt.h b/src/coreclr/src/pal/inc/rt/safecrt.h index fa30a15..58ea8f3 100644 --- a/src/coreclr/src/pal/inc/rt/safecrt.h +++ b/src/coreclr/src/pal/inc/rt/safecrt.h @@ -332,17 +332,6 @@ typedef int errno_t; /* standard */ return EINVAL; #endif -/* MBCS handling: change these definitions if you do not need to support mbcs strings */ -#if !defined(_SAFECRT__ISMBBLEAD) -#define _SAFECRT__ISMBBLEAD(_Character) \ - _ismbblead(_Character) -#endif - -#if !defined(_SAFECRT__MBSDEC) -#define _SAFECRT__MBSDEC(_String, _Current) \ - _mbsdec(_String, _Current) -#endif - _SAFECRT__EXTERN_C void __cdecl _invalid_parameter(const WCHAR *_Message, const WCHAR *_FunctionName, const WCHAR *_FileName, unsigned int _LineNumber, uintptr_t _Reserved); @@ -373,7 +362,7 @@ void __cdecl _invalid_parameter(const WCHAR *_Message, const WCHAR *_FunctionNam #if _SAFECRT_DEFINE_TCS_MACROS /* _tcs macros */ -#if !defined(_UNICODE) && !defined(UNICODE) && !defined(_MBCS) +#if !defined(_UNICODE) && !defined(UNICODE) #define _tcscpy_s strcpy_s #define _tcsncpy_s strncpy_s @@ -382,13 +371,7 @@ void __cdecl _invalid_parameter(const WCHAR *_Message, const WCHAR *_FunctionNam #define _tcsset_s _strset_s #define _tcsnset_s _strnset_s #define _tcstok_s strtok_s -#define _tmakepath_s _makepath_s -#define _tsplitpath_s _splitpath_s -#define _stprintf_s sprintf_s -#define _sntprintf_s _snprintf_s #define _vsntprintf_s _vsnprintf_s -#define _tscanf_s scanf_s -#define _tsscanf_s sscanf_s #elif defined(_UNICODE) || defined(UNICODE) @@ -406,22 +389,6 @@ void __cdecl _invalid_parameter(const WCHAR *_Message, const WCHAR *_FunctionNam #define _tscanf_s wscanf_s #define _tsscanf_s swscanf_s -#elif defined(_MBCS) - -#define _tcscpy_s _mbscpy_s -#define _tcsncpy_s _mbsnbcpy_s -#define _tcscat_s _mbscat_s -#define _tcsncat_s _mbsnbcat_s -#define _tcsset_s _mbsset_s -#define _tcsnset_s _mbsnbset_s -#define _tcstok_s _mbstok_s -#define _tmakepath_s _makepath_s -#define _tsplitpath_s _splitpath_s -#define _stprintf_s sprintf_s -#define _sntprintf_s _snprintf_s -#define _tscanf_s scanf_s -#define _tsscanf_s sscanf_s - #else #error We should not get here... @@ -524,64 +491,6 @@ errno_t __cdecl wcscpy_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src) #endif -/* _mbscpy_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - -_SAFECRT__EXTERN_C -errno_t __cdecl _mbscpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _mbscpy_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src) -{ - return _mbscpy_s(_Dst, _SizeInBytes, _Src); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _mbscpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src) -{ - unsigned char *p; - size_t available; - - /* validation section */ - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes); - - p = _Dst; - available = _SizeInBytes; - while ((*p++ = *_Src++) != 0 && --available > 0) - { - } - - if (available == 0) - { - if (*_Src == 0 && _SAFECRT__ISMBBLEAD(p[-1])) - { - /* the source string ended with a lead byte: we remove it */ - p[-1] = 0; - return 0; - } - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); - } - if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-2])) - { - /* the source string ended with a lead byte: we remove it */ - p[-2] = 0; - available++; - } - _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); - return 0; -} - -#endif - -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ - /* strncpy_s */ /* * strncpy_s, wcsncpy_s copy at max _Count characters from string _Src into _Dst; @@ -734,212 +643,6 @@ errno_t __cdecl wcsncpy_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src, s #endif -/* _mbsnbcpy_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - -_SAFECRT__EXTERN_C -errno_t __cdecl _mbsnbcpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInBytes); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _mbsnbcpy_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src, size_t _CountInBytes) -{ - return _mbsnbcpy_s(_Dst, _SizeInBytes, _Src, _CountInBytes); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _mbsnbcpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInBytes) -{ - unsigned char *p; - size_t available; - - if (_CountInBytes == 0 && _Dst == nullptr && _SizeInBytes == 0) - { - /* this case is allowed; nothing to do */ - return 0; - } - - /* validation section */ - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - if (_CountInBytes == 0) - { - /* notice that the source string pointer can be nullptr in this case */ - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - return 0; - } - _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes); - - p = _Dst; - available = _SizeInBytes; - if (_CountInBytes == _TRUNCATE) - { - while ((*p++ = *_Src++) != 0 && --available > 0) - { - } - } - else - { - while ((*p++ = *_Src++) != 0 && --available > 0 && --_CountInBytes > 0) - { - } - if (_CountInBytes == 0) - { - *p++ = 0; - } - } - - if (available == 0) - { - if ((*_Src == 0 || _CountInBytes == 1) && _SAFECRT__ISMBBLEAD(p[-1])) - { - /* the source string ended with a lead byte: we remove it */ - p[-1] = 0; - return 0; - } - if (_CountInBytes == _TRUNCATE) - { - if (_SizeInBytes > 1 && _SAFECRT__ISMBBLEAD(_Dst[_SizeInBytes - 2])) - { - _Dst[_SizeInBytes - 2] = 0; - _SAFECRT__FILL_BYTE(_Dst[_SizeInBytes - 1]); - } - else - { - _Dst[_SizeInBytes - 1] = 0; - } - return STRUNCATE; - } - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); - } - if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-2])) - { - /* the source string ended with a lead byte: we remove it */ - p[-2] = 0; - available++; - } - _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); - return 0; -} - -#endif - -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ - -/* _mbsncpy_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - -_SAFECRT__EXTERN_C -errno_t __cdecl _mbsncpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInChars); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _mbsncpy_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src, size_t _CountInChars) -{ - return _mbsncpy_s(_Dst, _SizeInBytes, _Src, _CountInChars); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _mbsncpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInChars) -{ - unsigned char *p; - size_t available; - - if (_CountInChars == 0 && _Dst == nullptr && _SizeInBytes == 0) - { - /* this case is allowed; nothing to do */ - return 0; - } - - /* validation section */ - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - if (_CountInChars == 0) - { - /* notice that the source string pointer can be nullptr in this case */ - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - return 0; - } - _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes); - - p = _Dst; - available = _SizeInBytes; - if (_CountInChars == _TRUNCATE) - { - while ((*p++ = *_Src++) != 0 && --available > 0) - { - } - } - else - { - do - { - if (_SAFECRT__ISMBBLEAD(*_Src)) - { - if (_Src[1] == 0) - { - /* the source string ended with a lead byte: we remove it */ - *p = 0; - break; - } - if (available <= 2) - { - /* not enough space */ - available = 0; - break; - } - *p++ = *_Src++; - *p++ = *_Src++; - available -= 2; - } - else - { - if ((*p++ = *_Src++) == 0 || --available == 0) - { - break; - } - } - } - while (--_CountInChars > 0); - if (_CountInChars == 0) - { - *p++ = 0; - } - } - - if (available == 0) - { - if (_CountInChars == _TRUNCATE) - { - if (_SizeInBytes > 1 && _SAFECRT__ISMBBLEAD(_Dst[_SizeInBytes - 2])) - { - _Dst[_SizeInBytes - 2] = 0; - _SAFECRT__FILL_BYTE(_Dst[_SizeInBytes - 1]); - } - else - { - _Dst[_SizeInBytes - 1] = 0; - } - return STRUNCATE; - } - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); - } - _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); - return 0; -} - -#endif - -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ - /* strcat_s */ /* * strcat_s, wcscat_s append string _Src to _Dst; @@ -1052,93 +755,6 @@ errno_t __cdecl wcscat_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src) #endif -/* _mbscat_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - -_SAFECRT__EXTERN_C -errno_t __cdecl _mbscat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _mbscat_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src) -{ - return _mbscat_s(_Dst, _SizeInBytes, _Src); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _mbscat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src) -{ - unsigned char *p; - size_t available; - - /* validation section */ - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes); - - p = _Dst; - available = _SizeInBytes; - while (available > 0 && *p != 0) - { - p++; - available--; - } - - if (available == 0) - { - if (*p == 0 && _SAFECRT__ISMBBLEAD(p[-1])) - { - /* the original string ended with a lead byte: we remove it */ - p--; - *p = 0; - available = 1; - } - else - { - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes); - } - } - if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-1])) - { - /* the original string ended with a lead byte: we remove it */ - p--; - *p = 0; - available++; - } - - while ((*p++ = *_Src++) != 0 && --available > 0) - { - } - - if (available == 0) - { - if (*_Src == 0 && _SAFECRT__ISMBBLEAD(p[-1])) - { - /* the source string ended with a lead byte: we remove it */ - p[-1] = 0; - return 0; - } - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); - } - if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-2])) - { - /* the source string ended with a lead byte: we remove it */ - p[-2] = 0; - available++; - } - _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); - return 0; -} - -#endif - -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ - /* strncat_s */ /* * strncat_s, wcsncat_s append at max _Count characters from string _Src to _Dst; @@ -1307,260 +923,6 @@ errno_t __cdecl wcsncat_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src, s #endif -/* _mbsnbcat_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - -_SAFECRT__EXTERN_C -errno_t __cdecl _mbsnbcat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInBytes); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _mbsnbcat_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src, size_t _CountInBytes) -{ - return _mbsnbcat_s(_Dst, _SizeInBytes, _Src, size_t _CountInBytes); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _mbsnbcat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInBytes) -{ - unsigned char *p; - size_t available; - if (_CountInBytes == 0 && _Dst == nullptr && _SizeInBytes == 0) - { - /* this case is allowed; nothing to do */ - return 0; - } - /* validation section */ - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - if (_CountInBytes != 0) - { - _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes); - } - - p = _Dst; - available = _SizeInBytes; - while (available > 0 && *p != 0) - { - p++; - available--; - } - - if (available == 0) - { - if (*p == 0 && _SAFECRT__ISMBBLEAD(p[-1])) - { - /* the original string ended with a lead byte: we remove it */ - p--; - *p = 0; - available = 1; - } - else - { - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes); - } - } - if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-1])) - { - /* the original string ended with a lead byte: we remove it */ - p--; - *p = 0; - available++; - } - - if (_CountInBytes == _TRUNCATE) - { - while ((*p++ = *_Src++) != 0 && --available > 0) - { - } - } - else - { - while (_CountInBytes > 0 && (*p++ = *_Src++) != 0 && --available > 0) - { - _CountInBytes--; - } - if (_CountInBytes == 0) - { - *p++ = 0; - } - } - - if (available == 0) - { - if ((*_Src == 0 || _CountInBytes == 1) && _SAFECRT__ISMBBLEAD(p[-1])) - { - /* the source string ended with a lead byte: we remove it */ - p[-1] = 0; - return 0; - } - if (_CountInBytes == _TRUNCATE) - { - if (_SizeInBytes > 1 && _SAFECRT__ISMBBLEAD(_Dst[_SizeInBytes - 2])) - { - _Dst[_SizeInBytes - 2] = 0; - _SAFECRT__FILL_BYTE(_Dst[_SizeInBytes - 1]); - } - else - { - _Dst[_SizeInBytes - 1] = 0; - } - return STRUNCATE; - } - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); - } - if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-2])) - { - /* the source string ended with a lead byte: we remove it */ - p[-2] = 0; - available++; - } - _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); - return 0; -} - -#endif - -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ - -/* _mbsncat_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - -_SAFECRT__EXTERN_C -errno_t __cdecl _mbsncat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInChars); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _mbsncat_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src, size_t _CountInChars) -{ - return _mbsncat_s(_Dst, _SizeInBytes, _Src, size_t _CountInChars); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _mbsncat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInChars) -{ - unsigned char *p; - size_t available; - if (_CountInChars == 0 && _Dst == nullptr && _SizeInBytes == 0) - { - /* this case is allowed; nothing to do */ - return 0; - } - /* validation section */ - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - if (_CountInChars != 0) - { - _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes); - } - - p = _Dst; - available = _SizeInBytes; - while (available > 0 && *p != 0) - { - p++; - available--; - } - - if (available == 0) - { - if (*p == 0 && _SAFECRT__ISMBBLEAD(p[-1])) - { - /* the original string ended with a lead byte: we remove it */ - p--; - *p = 0; - available = 1; - } - else - { - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes); - } - } - if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-1])) - { - /* the original string ended with a lead byte: we remove it */ - p--; - *p = 0; - available++; - } - - if (_CountInChars == _TRUNCATE) - { - while ((*p++ = *_Src++) != 0 && --available > 0) - { - } - } - else - { - while (_CountInChars > 0) - { - if (_SAFECRT__ISMBBLEAD(*_Src)) - { - if (_Src[1] == 0) - { - /* the source string ended with a lead byte: we remove it */ - *p = 0; - break; - } - if (available <= 2) - { - /* not enough space */ - available = 0; - break; - } - *p++ = *_Src++; - *p++ = *_Src++; - available -= 2; - } - else - { - if ((*p++ = *_Src++) == 0 || --available == 0) - { - break; - } - } - _CountInChars--; - } - if (_CountInChars == 0) - { - *p++ = 0; - } - } - - if (available == 0) - { - if (_CountInChars == _TRUNCATE) - { - if (_SizeInBytes > 1 && _SAFECRT__ISMBBLEAD(_Dst[_SizeInBytes - 2])) - { - _Dst[_SizeInBytes - 2] = 0; - _SAFECRT__FILL_BYTE(_Dst[_SizeInBytes - 1]); - } - else - { - _Dst[_SizeInBytes - 1] = 0; - } - return STRUNCATE; - } - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); - } - _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); - return 0; -} - -#endif - -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ /* _strset_s */ /* @@ -1650,101 +1012,6 @@ errno_t __cdecl _wcsset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value) #endif -/* _mbsset_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - -_SAFECRT__EXTERN_C -errno_t __cdecl _mbsset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _mbsset_s(unsigned char (&_Dst)[_SizeInBytes], unsigned int _Value) -{ - return _mbsset_s(_Dst, _SizeInBytes, _Value); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _mbsset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value) -{ - int mbcs_error = 0; - unsigned char *p; - size_t available; - unsigned char highval, lowval; - - /* validation section */ - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - - p = _Dst; - available = _SizeInBytes; - highval = (unsigned char)(_Value >> 8); - lowval = (unsigned char)(_Value & 0x00ff); - if (highval != 0) - { - if (_SAFECRT__ISMBBLEAD(highval) && lowval != 0) - { - while (*p != 0 && --available > 0) - { - if (p[1] == 0) - { - /* do not orphan leadbyte */ - *p++ = ' '; - break; - } - *p++ = highval; - if (--available == 0) - { - break; - } - *p++ = lowval; - } - } - else - { - mbcs_error = 1; - highval = 0; - lowval = ' '; - } - } - else - { - if (_SAFECRT__ISMBBLEAD(lowval)) - { - mbcs_error = 1; - lowval = ' '; - } - } - if (highval == 0) - { - while (*p != 0 && --available > 0) - { - *p++ = lowval; - } - } - - if (available == 0) - { - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes); - } - _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); - if (mbcs_error) - { - _SAFECRT__SET_ERRNO(EILSEQ); return EILSEQ; - } - else - { - return 0; - } -} - -#endif - -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ - /* _strnset_s */ /* * _strnset_s, _wcsnset_s ; @@ -1765,368 +1032,93 @@ errno_t __cdecl _strnset_s(char (&_Dst)[_SizeInBytes], int _Value, size_t _Count #if _SAFECRT_USE_INLINES || _SAFECRT_IMPL _SAFECRT__INLINE -errno_t __cdecl _strnset_s(char *_Dst, size_t _SizeInBytes, int _Value, size_t _Count) -{ - char *p; - size_t available; - - /* validation section */ - if (_Count == 0 && _Dst == nullptr && _SizeInBytes == 0) - { - /* this case is allowed; nothing to do */ - return 0; - } - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - - p = _Dst; - available = _SizeInBytes; - while (*p != 0 && _Count > 0 && --available > 0) - { - *p++ = (char)_Value; - --_Count; - } - - if (available == 0) - { - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes); - } - if (_Count == 0) - { - *p = 0; - } - _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); - return 0; -} - -#endif - -/* _wcsnset_s */ -_SAFECRT__EXTERN_C -errno_t __cdecl _wcsnset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value, size_t _Count); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _wcsnset_s(WCHAR (&_Dst)[_SizeInWords], WCHAR _Value, size_t _Count) -{ - return _wcsnset_s(_Dst, _SizeInWords, _Value, _Count); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _wcsnset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value, size_t _Count) -{ - WCHAR *p; - size_t available; - - /* validation section */ - if (_Count == 0 && _Dst == nullptr && _SizeInWords == 0) - { - /* this case is allowed; nothing to do */ - return 0; - } - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords); - - p = _Dst; - available = _SizeInWords; - while (*p != 0 && _Count > 0 && --available > 0) - { - *p++ = (WCHAR)_Value; - --_Count; - } - - if (available == 0) - { - _SAFECRT__RESET_STRING(_Dst, _SizeInWords); - _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInWords); - } - if (_Count == 0) - { - *p = 0; - } - _SAFECRT__FILL_STRING(_Dst, _SizeInWords, _SizeInWords - available + 1); - return 0; -} - -#endif - -/* _mbsnbset_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - -_SAFECRT__EXTERN_C -errno_t __cdecl _mbsnbset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, size_t _CountInBytes); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _mbsnbset_s(unsigned char (&_Dst)[_SizeInBytes], unsigned int _Value, size_t _CountInBytes) -{ - return _mbsnbset_s(_Dst, _SizeInBytes, _Value, _CountInBytes); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _mbsnbset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, size_t _CountInBytes) -{ - int mbcs_error = 0; - unsigned char *p; - size_t available; - unsigned char highval, lowval; - - /* validation section */ - if (_CountInBytes == 0 && _Dst == nullptr && _SizeInBytes == 0) - { - /* this case is allowed; nothing to do */ - return 0; - } - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - - p = _Dst; - available = _SizeInBytes; - highval = (unsigned char)(_Value >> 8); - lowval = (unsigned char)(_Value & 0x00ff); - if (highval != 0) - { - if (_SAFECRT__ISMBBLEAD(highval) && lowval != 0) - { - while (*p != 0 && _CountInBytes > 0 && --available > 0) - { - if (_CountInBytes == 1 || p[1] == 0) - { - /* do not orphan leadbyte */ - *p++ = ' '; - --_CountInBytes; - break; - } - *p++ = highval; - if (--available == 0) - { - break; - } - *p++ = lowval; - _CountInBytes -= 2; - } - } - else - { - mbcs_error = 1; - highval = 0; - lowval = ' '; - } - } - else - { - if (_SAFECRT__ISMBBLEAD(lowval)) - { - mbcs_error = 1; - lowval = ' '; - } - } - if (highval == 0) - { - while (*p != 0 && available > 0 && _CountInBytes > 0) - { - *p++ = lowval; - --available; - --_CountInBytes; - } - } - if (available == 0) - { - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes); - } - if (_CountInBytes == 0) - { - *p = 0; - } - _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); - if (mbcs_error) - { - _SAFECRT__SET_ERRNO(EILSEQ); return EILSEQ; - } - else - { - return 0; - } -} - -#endif - -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ - -/* _mbsnset_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - -_SAFECRT__EXTERN_C -errno_t __cdecl _mbsnset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, size_t _CountInChars); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _mbsnset_s(unsigned char (&_Dst)[_SizeInBytes], unsigned int _Value, size_t _CountInChars) -{ - return _mbsnset_s(_Dst, _SizeInBytes, _Value, _CountInChars); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _mbsnset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, size_t _CountInChars) -{ - int mbcs_error = 0; - unsigned char *p; - size_t available; - unsigned char highval, lowval; - - /* validation section */ - if (_CountInChars == 0 && _Dst == nullptr && _SizeInBytes == 0) - { - /* this case is allowed; nothing to do */ - return 0; - } - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - - p = _Dst; - available = _SizeInBytes; - highval = (unsigned char)(_Value >> 8); - lowval = (unsigned char)(_Value & 0x00ff); - if (highval != 0) - { - if (_SAFECRT__ISMBBLEAD(highval) && lowval != 0) - { - while (*p != 0 && _CountInChars > 0 && --available > 0) - { - if (p[1] == 0) - { - /* do not orphan leadbyte */ - *p++ = ' '; - break; - } - *p++ = highval; - if (--available == 0) - { - break; - } - *p++ = lowval; - --_CountInChars; - } - } - else - { - mbcs_error = 1; - highval = 0; - lowval = ' '; - } - } - else +errno_t __cdecl _strnset_s(char *_Dst, size_t _SizeInBytes, int _Value, size_t _Count) +{ + char *p; + size_t available; + + /* validation section */ + if (_Count == 0 && _Dst == nullptr && _SizeInBytes == 0) { - if (_SAFECRT__ISMBBLEAD(lowval)) - { - mbcs_error = 1; - lowval = ' '; - } + /* this case is allowed; nothing to do */ + return 0; } - if (highval == 0) + _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); + + p = _Dst; + available = _SizeInBytes; + while (*p != 0 && _Count > 0 && --available > 0) { - while (*p != 0 && available > 0 && _CountInChars > 0) - { - *p++ = lowval; - --available; - --_CountInChars; - } + *p++ = (char)_Value; + --_Count; } + if (available == 0) { _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes); } - if (_CountInChars == 0) + if (_Count == 0) { *p = 0; } _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1); - if (mbcs_error) - { - _SAFECRT__SET_ERRNO(EILSEQ); return EILSEQ; - } - else - { - return 0; - } + return 0; } #endif -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ - -/* _mbccpy_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - +/* _wcsnset_s */ _SAFECRT__EXTERN_C -errno_t __cdecl _mbccpy_s(unsigned char *_Dst, size_t _SizeInBytes, int *_PCopied, const unsigned char *_Src); +errno_t __cdecl _wcsnset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value, size_t _Count); #if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template +template inline -errno_t __cdecl _mbccpy_s(unsigned char (&_Dst)[_SizeInBytes], int *_PCopied, const unsigned char *_Src) +errno_t __cdecl _wcsnset_s(WCHAR (&_Dst)[_SizeInWords], WCHAR _Value, size_t _Count) { - return _mbccpy_s(_Dst, _SizeInBytes, _PCopied, _Src); + return _wcsnset_s(_Dst, _SizeInWords, _Value, _Count); } #endif #if _SAFECRT_USE_INLINES || _SAFECRT_IMPL _SAFECRT__INLINE -errno_t __cdecl _mbccpy_s(unsigned char *_Dst, size_t _SizeInBytes, int *_PCopied, const unsigned char *_Src) +errno_t __cdecl _wcsnset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value, size_t _Count) { + WCHAR *p; + size_t available; + /* validation section */ - if (_PCopied != nullptr) { *_PCopied = 0; }; - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - if (_Src == nullptr) + if (_Count == 0 && _Dst == nullptr && _SizeInWords == 0) { - *_Dst = '\0'; - _SAFECRT__RETURN_EINVAL; + /* this case is allowed; nothing to do */ + return 0; } + _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords); - /* copy */ - if (_SAFECRT__ISMBBLEAD(*_Src)) + p = _Dst; + available = _SizeInWords; + while (*p != 0 && _Count > 0 && --available > 0) { - if (_Src[1] == '\0') - { - /* the source string contained a lead byte followed by the null terminator: - we copy only the null terminator and return EILSEQ to indicate the - malformed char */ - *_Dst = '\0'; - if (_PCopied != nullptr) { *_PCopied = 1; }; - _SAFECRT__SET_ERRNO(EILSEQ); return EILSEQ; - } - if (_SizeInBytes < 2) - { - *_Dst = '\0'; - _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); - } - *_Dst++ = *_Src++; - *_Dst = *_Src; - if (_PCopied != nullptr) { *_PCopied = 2; }; + *p++ = (WCHAR)_Value; + --_Count; } - else + + if (available == 0) { - *_Dst = *_Src; - if (_PCopied != nullptr) { *_PCopied = 1; }; + _SAFECRT__RESET_STRING(_Dst, _SizeInWords); + _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInWords); } - + if (_Count == 0) + { + *p = 0; + } + _SAFECRT__FILL_STRING(_Dst, _SizeInWords, _SizeInWords - available + 1); return 0; } -#endif -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ +#endif /* strtok_s */ /* @@ -2275,129 +1267,6 @@ WCHAR * __cdecl wcstok_s(WCHAR *_String, const WCHAR *_Control, WCHAR **_Context } #endif -/* _mbstok_s */ -#if _SAFECRT_DEFINE_MBS_FUNCTIONS - -_SAFECRT__EXTERN_C -unsigned char * __cdecl _mbstok_s(unsigned char *_String, const unsigned char *_Control, unsigned char **_Context); - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -unsigned char * __cdecl _mbstok_s(unsigned char *_String, const unsigned char *_Control, unsigned char **_Context) -{ - unsigned char *token; - const unsigned char *ctl; - int dbc; - - /* validation section */ - _SAFECRT__VALIDATE_POINTER_ERROR_RETURN(_Context, EINVAL, nullptr); - _SAFECRT__VALIDATE_POINTER_ERROR_RETURN(_Control, EINVAL, nullptr); - _SAFECRT__VALIDATE_CONDITION_ERROR_RETURN(_String != nullptr || *_Context != nullptr, EINVAL, nullptr); - - /* If string==nullptr, continue with previous string */ - if (!_String) - { - _String = *_Context; - } - - /* Find beginning of token (skip over leading delimiters). Note that - * there is no token iff this loop sets string to point to the terminal null. */ - for ( ; *_String != 0; _String++) - { - for (ctl = _Control; *ctl != 0; ctl++) - { - if (_SAFECRT__ISMBBLEAD(*ctl)) - { - if (*ctl == *_String && (ctl[1] == 0 || ctl[1] == _String[1])) - { - break; - } - ctl++; - } - else - { - if (*ctl == *_String) - { - break; - } - } - } - if (*ctl == 0) - { - break; - } - if (_SAFECRT__ISMBBLEAD(*_String)) - { - _String++; - if (*_String == 0) - { - break; - } - } - } - - token = _String; - - /* Find the end of the token. If it is not the end of the string, - * put a null there. */ - for ( ; *_String != 0; _String++) - { - for (ctl = _Control, dbc = 0; *ctl != 0; ctl++) - { - if (_SAFECRT__ISMBBLEAD(*ctl)) - { - if (*ctl == *_String && (ctl[1] == 0 || ctl[1] == _String[1])) - { - dbc = 1; - break; - } - ctl++; - } - else - { - if (*ctl == *_String) - { - break; - } - } - } - if (*ctl != 0) - { - *_String++ = 0; - if (dbc && ctl[1] != 0) - { - *_String++ = 0; - } - break; - } - if (_SAFECRT__ISMBBLEAD(*_String)) - { - _String++; - if (*_String == 0) - { - break; - } - } - } - - /* Update the context */ - *_Context = _String; - - /* Determine if a token has been found. */ - if (token == _String) - { - return nullptr; - } - else - { - return token; - } -} -#endif - -#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ - #ifndef PAL_STDCPP_COMPAT /* strnlen */ /* @@ -2432,142 +1301,23 @@ size_t __cdecl wcsnlen(const WCHAR *inString, size_t inMaxSize); #if _SAFECRT_USE_INLINES || _SAFECRT_IMPL -_SAFECRT__INLINE -size_t __cdecl wcsnlen(const WCHAR *inString, size_t inMaxSize) -{ - size_t n; - - /* Note that we do not check if s == nullptr, because we do not - * return errno_t... - */ - - for (n = 0; n < inMaxSize && *inString; n++, inString++) - ; - - return n; -} - -#endif -#endif // PAL_STDCPP_COMPAT - -/* _makepath_s */ -/* - * _makepath_s, _wmakepath_s build up a path starting from the specified components; - * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in _Dst; - * any of _Drive, _Dir, _Filename and _Ext can be nullptr - */ -_SAFECRT__EXTERN_C -errno_t __cdecl _makepath_s(char *_Dst, size_t _SizeInBytes, const char *_Drive, const char *_Dir, const char *_Filename, const char *_Ext); - -#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS -template -inline -errno_t __cdecl _makepath_s(char (&_Dst)[_SizeInBytes], const char *_Drive, const char *_Dir, const char *_Filename, const char *_Ext) -{ - return _makepath_s(_Dst, _SizeInBytes, _Drive, _Dir, _Filename, _Ext); -} -#endif - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _makepath_s(char *_Dst, size_t _SizeInBytes, const char *_Drive, const char *_Dir, const char *_Filename, const char *_Ext) -{ - size_t written; - const char *p; - char *d; - - /* validation section */ - _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes); - - /* copy drive */ - written = 0; - d = _Dst; - if (_Drive != nullptr && *_Drive != 0) - { - written += 2; - if(written >= _SizeInBytes) - { - goto error_return; - } - *d++ = *_Drive; - *d++ = ':'; - } - - /* copy dir */ - p = _Dir; - if (p != nullptr && *p != 0) - { - do { - if(++written >= _SizeInBytes) - { - goto error_return; - } - *d++ = *p++; - } while (*p != 0); - - p = (const char *)_SAFECRT__MBSDEC((const unsigned char *)_Dir, (const unsigned char *)p); - if (*p != '/' && *p != '\\') - { - if(++written >= _SizeInBytes) - { - goto error_return; - } - *d++ = '\\'; - } - } - - /* copy fname */ - p = _Filename; - if (p != nullptr) - { - while (*p != 0) - { - if(++written >= _SizeInBytes) - { - goto error_return; - } - *d++ = *p++; - } - } - - /* copy extension; check to see if a '.' needs to be inserted */ - p = _Ext; - if (p != nullptr) - { - if (*p != 0 && *p != '.') - { - if(++written >= _SizeInBytes) - { - goto error_return; - } - *d++ = '.'; - } - while (*p != 0) - { - if(++written >= _SizeInBytes) - { - goto error_return; - } - *d++ = *p++; - } - } +_SAFECRT__INLINE +size_t __cdecl wcsnlen(const WCHAR *inString, size_t inMaxSize) +{ + size_t n; - if(++written > _SizeInBytes) - { - goto error_return; - } - *d = 0; - _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, written); - return 0; + /* Note that we do not check if s == nullptr, because we do not + * return errno_t... + */ -error_return: - _SAFECRT__RESET_STRING(_Dst, _SizeInBytes); - _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes); - /* should never happen, but compiler can't tell */ - return EINVAL; + for (n = 0; n < inMaxSize && *inString; n++, inString++) + ; + + return n; } + #endif +#endif // PAL_STDCPP_COMPAT /* _wmakepath_s */ _SAFECRT__EXTERN_C @@ -2683,245 +1433,6 @@ error_return: } #endif -/* _splitpath_s */ -/* - * _splitpath_s, _wsplitpath_s decompose a path into the specified components; - * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in - * any of _Drive, _Dir, _Filename and _Ext; - * any of _Drive, _Dir, _Filename and _Ext can be nullptr, but the correspondent size must - * be set to 0, e.g. (_Drive == nullptr && _DriveSize == 0) is allowed, but - * (_Drive == nullptr && _DriveSize != 0) is considered an invalid parameter - */ -_SAFECRT__EXTERN_C -errno_t __cdecl _splitpath_s( - const char *_Path, - char *_Drive, size_t _DriveSize, - char *_Dir, size_t _DirSize, - char *_Filename, size_t _FilenameSize, - char *_Ext, size_t _ExtSize -); - -/* no C++ overload for _splitpath_s */ - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -errno_t __cdecl _splitpath_s( - const char *_Path, - char *_Drive, size_t _DriveSize, - char *_Dir, size_t _DirSize, - char *_Filename, size_t _FilenameSize, - char *_Ext, size_t _ExtSize -) -{ - const char *tmp; - const char *last_slash; - const char *dot; - int drive_set = 0; - size_t length = 0; - int bEinval = 0; - - /* validation section */ - _SAFECRT__VALIDATE_POINTER(_Path); - if ((_Drive == nullptr && _DriveSize != 0) || (_Drive != nullptr && _DriveSize == 0)) - { - goto error_einval; - } - if ((_Dir == nullptr && _DirSize != 0) || (_Dir != nullptr && _DirSize == 0)) - { - goto error_einval; - } - if ((_Filename == nullptr && _FilenameSize != 0) || (_Filename != nullptr && _FilenameSize == 0)) - { - goto error_einval; - } - if ((_Ext == nullptr && _ExtSize != 0) || (_Ext != nullptr && _ExtSize == 0)) - { - goto error_einval; - } - - /* check if _Path begins with the longpath prefix */ - if (_Path[0] == '\\' && _Path[1] == '\\' && _Path[2] == '?' && _Path[3] == '\\') - { - _Path += 4; - } - - /* extract drive letter and ':', if any */ - if (!drive_set) - { - size_t skip = _MAX_DRIVE - 2; - tmp = _Path; - while (skip > 0 && *tmp != 0) - { - skip--; - tmp++; - } - if (*tmp == ':') - { - if (_Drive != nullptr) - { - if (_DriveSize < _MAX_DRIVE) - { - goto error_erange; - } - strncpy_s(_Drive, _DriveSize, _Path, _MAX_DRIVE - 1); - } - _Path = tmp + 1; - } - else - { - if (_Drive != nullptr) - { - _SAFECRT__RESET_STRING(_Drive, _DriveSize); - } - } - } - - /* extract path string, if any. _Path now points to the first character - * of the path, if any, or the filename or extension, if no path was - * specified. Scan ahead for the last occurence, if any, of a '/' or - * '\' path separator character. If none is found, there is no path. - * We will also note the last '.' character found, if any, to aid in - * handling the extension. - */ - last_slash = nullptr; - dot = nullptr; - tmp = _Path; - for (; *tmp != 0; ++tmp) - { -#if _SAFECRT_DEFINE_MBS_FUNCTIONS -#pragma warning(push) -#pragma warning(disable:4127) - if (_SAFECRT__ISMBBLEAD(*tmp)) -#pragma warning(pop) -#else - if (0) -#endif - { - tmp++; - } - else - { - if (*tmp == '/' || *tmp == '\\') - { - /* point to one beyond for later copy */ - last_slash = tmp + 1; - } - else if (*tmp == '.') - { - dot = tmp; - } - } - } - - if (last_slash != nullptr) - { - /* found a path - copy up through last_slash or max characters - * allowed, whichever is smaller - */ - if (_Dir != nullptr) { - length = (size_t)(last_slash - _Path); - if (_DirSize <= length) - { - goto error_erange; - } - strncpy_s(_Dir, _DirSize, _Path, length); - } - _Path = last_slash; - } - else - { - /* there is no path */ - if (_Dir != nullptr) - { - _SAFECRT__RESET_STRING(_Dir, _DirSize); - } - } - - /* extract file name and extension, if any. Path now points to the - * first character of the file name, if any, or the extension if no - * file name was given. Dot points to the '.' beginning the extension, - * if any. - */ - if (dot != nullptr && (dot >= _Path)) - { - /* found the marker for an extension - copy the file name up to the '.' */ - if (_Filename) - { - length = (size_t)(dot - _Path); - if (_FilenameSize <= length) - { - goto error_erange; - } - strncpy_s(_Filename, _FilenameSize, _Path, length); - } - /* now we can get the extension - remember that tmp still points - * to the terminating nullptr character of path. - */ - if (_Ext) - { - length = (size_t)(tmp - dot); - if (_ExtSize <= length) - { - goto error_erange; - } - strncpy_s(_Ext, _ExtSize, dot, length); - } - } - else - { - /* found no extension, give empty extension and copy rest of - * string into fname. - */ - if (_Filename) - { - length = (size_t)(tmp - _Path); - if (_FilenameSize <= length) - { - goto error_erange; - } - strncpy_s(_Filename, _FilenameSize, _Path, length); - } - if (_Ext) - { - _SAFECRT__RESET_STRING(_Ext, _ExtSize); - } - } - - return 0; - -error_einval: - bEinval = 1; - -error_erange: - if (_Drive != nullptr && _DriveSize > 0) - { - _SAFECRT__RESET_STRING(_Drive, _DriveSize); - } - if (_Dir != nullptr && _DirSize > 0) - { - _SAFECRT__RESET_STRING(_Dir, _DirSize); - } - if (_Filename != nullptr && _FilenameSize > 0) - { - _SAFECRT__RESET_STRING(_Filename, _FilenameSize); - } - if (_Ext != nullptr && _ExtSize > 0) - { - _SAFECRT__RESET_STRING(_Ext, _ExtSize); - } - - if (bEinval) - { - _SAFECRT__RETURN_EINVAL; - } - - _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Strings, _StringSizes); - /* should never happen, but compiler can't tell */ - return EINVAL; -} -#endif - /* _wsplitpath_s */ _SAFECRT__EXTERN_C errno_t __cdecl _wsplitpath_s( @@ -3141,9 +1652,9 @@ error_erange: } #endif -/* sprintf_s, vsprintf_s */ +/* vsprintf_s */ /* - * sprintf_s, swprintf_s, vsprintf_s, vswprintf_s format a string and copy it into _Dst; + * swprintf_s, vsprintf_s, vswprintf_s format a string and copy it into _Dst; * need safecrt.lib and msvcrt.dll; * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in _Dst; * will call _SAFECRT_INVALID_PARAMETER if the format string is malformed; @@ -3154,32 +1665,18 @@ error_erange: * cannot be used without safecrt.lib */ _SAFECRT__EXTERN_C -int __cdecl sprintf_s(char *_Dst, size_t _SizeInBytes, const char *_Format, ...); -_SAFECRT__EXTERN_C int __cdecl vsprintf_s(char *_Dst, size_t _SizeInBytes, const char *_Format, va_list _ArgList); #if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS template inline -int __cdecl sprintf_s(char (&_Dst)[_SizeInBytes], const char *_Format, ...) -{ - int ret; - va_list _ArgList; - va_start(_ArgList, _Format); - ret = vsprintf_s(_Dst, _SizeInBytes, _Format, _ArgList); - va_end(_ArgList); - return ret; -} - -template -inline int __cdecl vsprintf_s(char (&_Dst)[_SizeInBytes], const char *_Format, va_list _ArgList) { return vsprintf_s(_Dst, _SizeInBytes, _Format, _ArgList); } #endif -/* no inline version of sprintf_s, vsprintf_s */ +/* no inline version of vsprintf_s */ /* swprintf_s, vswprintf_s */ _SAFECRT__EXTERN_C @@ -3210,9 +1707,9 @@ int __cdecl vswprintf_s(WCHAR (&_Dst)[_SizeInWords], const WCHAR *_Format, va_li /* no inline version of swprintf_s, vswprintf_s */ -/* _snprintf_s, _vsnprintf_s */ +/* _vsnprintf_s */ /* - * _snprintf_s, _snwprintf_s, _vsnprintf_s, _vsnwprintf_s format a string and copy at max _Count characters into _Dst; + * _snwprintf_s, _vsnprintf_s, _vsnwprintf_s format a string and copy at max _Count characters into _Dst; * need safecrt.lib and msvcrt.dll; * string _Dst will always be null-terminated; * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in _Dst; @@ -3230,25 +1727,13 @@ int __cdecl vswprintf_s(WCHAR (&_Dst)[_SizeInWords], const WCHAR *_Format, va_li #if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS template inline -int __cdecl _snprintf_s(char (&_Dst)[_SizeInBytes], size_t _Count, const char *_Format, ...) -{ - int ret; - va_list _ArgList; - va_start(_ArgList, _Format); - ret = _vsnprintf_s(_Dst, _SizeInBytes, _Count, _Format, _ArgList); - va_end(_ArgList); - return ret; -} - -template -inline int __cdecl _vsnprintf_s(char (&_Dst)[_SizeInBytes], size_t _Count, const char *_Format, va_list _ArgList) { return _vsnprintf_s(_Dst, _SizeInBytes, _Count, _Format, _ArgList); } #endif -/* no inline version of _snprintf_s, _vsnprintf_s */ +/* no inline version of _vsnprintf_s */ /* _snwprintf_s, _vsnwprintf_s */ _SAFECRT__EXTERN_C @@ -3277,27 +1762,6 @@ int __cdecl _vsnwprintf_s(char (&_Dst)[_SizeInWords], size_t _Count, const char /* no inline version of _snwprintf_s, _vsnwprintf_s */ -/* scanf_s */ -/* - * read formatted data from the standard input stream; - * need safecrt.lib and msvcrt.dll; - * will call _SAFECRT_INVALID_PARAMETER if the format string is malformed; - * for format types %s, %S, %[, %c and %C, in the argument list the buffer pointer - * need to be followed by the size of the buffer, e.g.: - * #define BUFFSIZE 100 - * char buff[BUFFSIZE]; - * scanf_s("%s", buff, BUFFSIZE); - * as scanf, returns the number of fields successfully converted and assigned; - * if a buffer field is too small, scanf set the buffer to the empty string and returns. - * do not support floating-point, for now - */ -_SAFECRT__EXTERN_C -int __cdecl scanf_s(const char *_Format, ...); - -/* no C++ overload for scanf_s */ - -/* no inline version of scanf_s */ - /* wscanf_s */ _SAFECRT__EXTERN_C int __cdecl wscanf_s(const WCHAR *_Format, ...); @@ -3306,14 +1770,6 @@ int __cdecl wscanf_s(const WCHAR *_Format, ...); /* no inline version of wscanf_s */ -/* sscanf_s */ -_SAFECRT__EXTERN_C -int __cdecl sscanf_s(const char *_String, const char *_Format, ...); - -/* no C++ overload for sscanf_s */ - -/* no inline version of sscanf_s */ - /* swscanf_s */ _SAFECRT__EXTERN_C int __cdecl swscanf_s(const WCHAR *_String, const WCHAR *_Format, ...); diff --git a/src/coreclr/src/pal/src/CMakeLists.txt b/src/coreclr/src/pal/src/CMakeLists.txt index 712dabf..1525e69 100644 --- a/src/coreclr/src/pal/src/CMakeLists.txt +++ b/src/coreclr/src/pal/src/CMakeLists.txt @@ -123,7 +123,6 @@ set(SOURCES cruntime/filecrt.cpp cruntime/malloc.cpp cruntime/math.cpp - cruntime/mbstring.cpp cruntime/misc.cpp cruntime/path.cpp cruntime/printf.cpp @@ -246,12 +245,12 @@ if(CLR_CMAKE_TARGET_OSX) ${LIBUNWIND_DAC_OBJECTS} ) - target_compile_definitions(coreclrpal_dac PUBLIC + target_compile_definitions(coreclrpal_dac PUBLIC "-D_XOPEN_SOURCE" "-DUNW_REMOTE_ONLY" ) - target_include_directories(coreclrpal_dac PUBLIC + target_include_directories(coreclrpal_dac PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/libunwind/include ${CMAKE_CURRENT_SOURCE_DIR}/libunwind/include/tdep ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/coreclr/src/pal/src/cruntime/mbstring.cpp b/src/coreclr/src/pal/src/cruntime/mbstring.cpp deleted file mode 100644 index 12d0cb0..0000000 --- a/src/coreclr/src/pal/src/cruntime/mbstring.cpp +++ /dev/null @@ -1,203 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*++ - - - -Module Name: - - mbstring.c - -Abstract: - - Implementation of the multi-byte string functions in the C runtime library that - are Windows specific. - -Implementation Notes: - - Assuming it is not possible to change multi-byte code page using - the PAL (_setmbcp does not seem to be required), these functions - should have a trivial implementation (treat as single-byte). If it - is possible, then support for multi-byte code pages will have to - be implemented before these functions can behave correctly for - multi-byte strings. - - - ---*/ - -#include "pal/palinternal.h" -#include "pal/dbgmsg.h" - -#include - -SET_DEFAULT_DEBUG_CHANNEL(CRT); - - -/*++ -Function: - _mbsinc - -Return Value - -Returns a pointer to the character that immediately follows string. - -Parameter - -string Character pointer - -Remarks - -The _mbsinc function returns a pointer to the first byte of the -multibyte character that immediately follows string. - ---*/ -unsigned char * -__cdecl -_mbsinc( - const unsigned char *string) -{ - unsigned char *ret; - - PERF_ENTRY(_mbsinc); - ENTRY("_mbsinc (string=%p)\n", string); - - if (string == NULL) - { - ret = NULL; - } - else - { - ret = (unsigned char *) string; - if (IsDBCSLeadByteEx(CP_ACP, *ret)) - { - ++ret; - } - ++ret; - } - - LOGEXIT("_mbsinc returning unsigned char* %p (%s)\n", ret, ret); - PERF_EXIT(_mbsinc); - return ret; -} - - -/*++ -Function: - _mbsninc - -Return Value - -Returns a pointer to string after string has been incremented by count -characters, or NULL if the supplied pointer is NULL. If count is -greater than or equal to the number of characters in string, the -result is undefined. - -Parameters - -string Source string -count Number of characters to increment string pointer - -Remarks - -The _mbsninc function increments string by count multibyte -characters. _mbsninc recognizes multibyte-character sequences -according to the multibyte code page currently in use. - ---*/ -unsigned char * -__cdecl -_mbsninc( - const unsigned char *string, size_t count) -{ - unsigned char *ret; - CPINFO cpinfo; - - PERF_ENTRY(_mbsninc); - ENTRY("_mbsninc (string=%p, count=%lu)\n", string, count); - if (string == NULL) - { - ret = NULL; - } - else - { - ret = (unsigned char *) string; - if (GetCPInfo(CP_ACP, &cpinfo) && cpinfo.MaxCharSize == 1) - { - ret += std::min(count, strlen((const char*)string)); - } - else - { - while (count-- && (*ret != 0)) - { - if (IsDBCSLeadByteEx(CP_ACP, *ret)) - { - ++ret; - } - ++ret; - } - } - } - LOGEXIT("_mbsninc returning unsigned char* %p (%s)\n", ret, ret); - PERF_EXIT(_mbsninc); - return ret; -} - -/*++ -Function: - _mbsdec - -Return Value - -_mbsdec returns a pointer to the character that immediately precedes -current; _mbsdec returns NULL if the value of start is greater than or -equal to that of current. - -Parameters - -start Pointer to first byte of any multibyte character in the source - string; start must precede current in the source string - -current Pointer to first byte of any multibyte character in the source - string; current must follow start in the source string - ---*/ -unsigned char * -__cdecl -_mbsdec( - const unsigned char *start, - const unsigned char *current) -{ - unsigned char *ret; - unsigned char *strPtr; - CPINFO cpinfo; - - PERF_ENTRY(_mbsdec); - ENTRY("_mbsdec (start=%p, current=%p)\n", start, current); - - if (current <= start) - { - ret = NULL; - } - else if (GetCPInfo(CP_ACP, &cpinfo) && cpinfo.MaxCharSize == 1) - { - ret = (unsigned char *) current - 1; - } - else - { - ret = strPtr = (unsigned char *) start; - while (strPtr < current) - { - ret = strPtr; - if (IsDBCSLeadByteEx(CP_ACP, *strPtr)) - { - ++strPtr; - } - ++strPtr; - } - } - LOGEXIT("_mbsdec returning unsigned int %p (%s)\n", ret, ret); - PERF_EXIT(_mbsdec); - return ret; -} diff --git a/src/coreclr/src/pal/src/locale/unicode.cpp b/src/coreclr/src/pal/src/locale/unicode.cpp index dea10ac..f29eabc 100644 --- a/src/coreclr/src/pal/src/locale/unicode.cpp +++ b/src/coreclr/src/pal/src/locale/unicode.cpp @@ -193,56 +193,6 @@ GetConsoleOutputCP( /*++ Function: -GetCPInfo - -See MSDN doc. ---*/ -BOOL -PALAPI -GetCPInfo( - IN UINT CodePage, - OUT LPCPINFO lpCPInfo) -{ - BOOL bRet = FALSE; - - PERF_ENTRY(GetCPInfo); - ENTRY("GetCPInfo(CodePage=%hu, lpCPInfo=%p)\n", CodePage, lpCPInfo); - - /*check if the input code page is valid*/ - if( CP_ACP != CodePage && CP_UTF8 != CodePage ) - { - /* error, invalid argument */ - ERROR("CodePage(%d) parameter is invalid\n",CodePage); - SetLastError( ERROR_INVALID_PARAMETER ); - goto done; - } - - /*check if the lpCPInfo parameter is valid. */ - if( !lpCPInfo ) - { - /* error, invalid argument */ - ERROR("lpCPInfo cannot be NULL\n" ); - SetLastError( ERROR_INVALID_PARAMETER ); - goto done; - } - - lpCPInfo->MaxCharSize = 4; - memset( lpCPInfo->LeadByte, 0, MAX_LEADBYTES ); - - /* Don't need to be set, according to the spec. */ - memset( lpCPInfo->DefaultChar, '?', MAX_DEFAULTCHAR ); - - bRet = TRUE; - -done: - LOGEXIT("GetCPInfo returns BOOL %d \n",bRet); - PERF_EXIT(GetCPInfo); - return bRet; -} - - -/*++ -Function: GetACP See MSDN doc. @@ -260,70 +210,6 @@ GetACP(VOID) return CP_UTF8; } - -/*++ -Function: -IsDBCSLeadByteEx - -See MSDN doc. ---*/ -BOOL -PALAPI -IsDBCSLeadByteEx( - IN UINT CodePage, - IN BYTE TestChar) -{ - CPINFO cpinfo; - SIZE_T i; - BOOL bRet = FALSE; - - PERF_ENTRY(IsDBCSLeadByteEx); - ENTRY("IsDBCSLeadByteEx(CodePage=%#x, TestChar=%d)\n", CodePage, TestChar); - - /* Get the lead byte info with respect to the given codepage*/ - if( !GetCPInfo( CodePage, &cpinfo ) ) - { - ERROR("Error CodePage(%#x) parameter is invalid\n", CodePage ); - SetLastError( ERROR_INVALID_PARAMETER ); - goto done; - } - - for( i=0; i < sizeof(cpinfo.LeadByte)/sizeof(cpinfo.LeadByte[0]); i += 2 ) - { - if( 0 == cpinfo.LeadByte[ i ] ) - { - goto done; - } - - /*check if the given char is in one of the lead byte ranges*/ - if( cpinfo.LeadByte[i] <= TestChar && TestChar<= cpinfo.LeadByte[i+1] ) - { - bRet = TRUE; - goto done; - } - } -done: - LOGEXIT("IsDBCSLeadByteEx returns BOOL %d\n",bRet); - PERF_EXIT(IsDBCSLeadByteEx); - return bRet; -} - -/*++ -Function: -IsDBCSLeadByte - -See MSDN doc. ---*/ -BOOL -PALAPI -IsDBCSLeadByte( - IN BYTE TestChar) -{ - // UNIXTODO: Implement this! - ERROR("Needs Implementation!!!"); - return FALSE; -} - /*++ Function: MultiByteToWideChar diff --git a/src/coreclr/src/pal/src/safecrt/input.inl b/src/coreclr/src/pal/src/safecrt/input.inl index 4e1d243..7b95193 100644 --- a/src/coreclr/src/pal/src/safecrt/input.inl +++ b/src/coreclr/src/pal/src/safecrt/input.inl @@ -45,31 +45,6 @@ #define _CVTBUFSIZE (309+40) /* # of digits in max. dp value + slop */ -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include - -//#ifndef _INC_INTERNAL_SAFECRT -//#include -//#endif /* _INC_INTERNAL_SAFECRT */ - -//#ifdef _MBCS -//#undef _MBCS -//#endif /* _MBCS */ -//#include - #define _MBTOWC(x,y,z) _minimal_chartowchar( x, y ) #define _istspace(x) isspace((unsigned char)x) diff --git a/src/coreclr/src/pal/src/safecrt/internal.h b/src/coreclr/src/pal/src/safecrt/internal.h index ab87904..9537f6f 100644 --- a/src/coreclr/src/pal/src/safecrt/internal.h +++ b/src/coreclr/src/pal/src/safecrt/internal.h @@ -459,10 +459,6 @@ _MRTIMP int __cdecl _onexit_process(_CPVFV); _MRTIMP int __cdecl _onexit_app_domain(_CPVFV); #endif /* MRTDLL */ -#ifdef _MBCS -int __cdecl __initmbctable(void); /* mbctype.c */ -#endif /* _MBCS */ - #ifndef _MANAGED_MAIN int __CRTDECL main(__in int _Argc, __in_ecount_z(_Argc) char ** _Argv, __in_z char ** _Env); int __CRTDECL wmain(__in int _Argc, __in_ecount_z(_Argc) char16_t ** _Argv, __in_z char16_t ** _Env); diff --git a/src/coreclr/src/pal/src/safecrt/internal_securecrt.h b/src/coreclr/src/pal/src/safecrt/internal_securecrt.h index f5ca89c..7d5fd1e 100644 --- a/src/coreclr/src/pal/src/safecrt/internal_securecrt.h +++ b/src/coreclr/src/pal/src/safecrt/internal_securecrt.h @@ -240,12 +240,6 @@ #define _RETURN_TRUNCATE \ return STRUNCATE -#define _SET_MBCS_ERROR \ - (errno = EILSEQ) - -#define _RETURN_MBCS_ERROR \ - return _SET_MBCS_ERROR - /* locale dependent */ #define _LOCALE_ARG \ _LocInfo @@ -256,26 +250,6 @@ #define _LOCALE_UPDATE \ _LocaleUpdate _LocUpdate(_LOCALE_ARG) -#define _ISMBBLEAD(_Character) \ - _ismbblead_l((_Character), _LocUpdate.GetLocaleT()) - -#define _MBSDEC(_String, _Current) \ - _mbsdec((_String), (_Current)) - -#define _ISMBBLEADPREFIX(_Result, _StringStart, _BytePtr) \ - { \ - unsigned char *_Tmp_VAR, *_StringStart_VAR, *_BytePtr_VAR; \ - \ - _StringStart_VAR = (_StringStart); \ - _BytePtr_VAR = (_BytePtr); \ - _Tmp_VAR = _BytePtr_VAR; \ - while ((_Tmp_VAR >= _StringStart_VAR) && _ISMBBLEAD(*_Tmp_VAR)) \ - { \ - _Tmp_VAR--; \ - } \ - (_Result) = ((_BytePtr_VAR - _Tmp_VAR) & 1) != 0; \ - } - #define _LOCALE_SHORTCUT_TEST \ _LocUpdate.GetLocaleT()->mbcinfo->ismbcodepage == 0 diff --git a/src/coreclr/src/pal/src/safecrt/makepath_s.cpp b/src/coreclr/src/pal/src/safecrt/makepath_s.cpp index 8b39a52..9d91cda 100644 --- a/src/coreclr/src/pal/src/safecrt/makepath_s.cpp +++ b/src/coreclr/src/pal/src/safecrt/makepath_s.cpp @@ -25,6 +25,4 @@ #define _SIZE _SizeInBytes #define _T(_Character) _Character -#define _MBS_SUPPORT 0 - #include "tmakepath_s.inl" diff --git a/src/coreclr/src/pal/src/safecrt/output.inl b/src/coreclr/src/pal/src/safecrt/output.inl index 9e90525..9f10dd6 100644 --- a/src/coreclr/src/pal/src/safecrt/output.inl +++ b/src/coreclr/src/pal/src/safecrt/output.inl @@ -79,11 +79,6 @@ Buffer size required to be passed to _gcvt, fcvt and other fp conversion routine #define _CLDCVT _cldcvt #endif /* _CLDCVT */ -#ifdef _MBCS -#undef _MBCS -#endif /* _MBCS */ -//#include - /* this macro defines a function which is private and as fast as possible: */ /* for example, in C 6.0, it might be static _fastcall near. */ #define LOCAL(x) static x __cdecl diff --git a/src/coreclr/src/pal/src/safecrt/safecrt_output_l.cpp b/src/coreclr/src/pal/src/safecrt/safecrt_output_l.cpp index 752ffea..7f00651 100644 --- a/src/coreclr/src/pal/src/safecrt/safecrt_output_l.cpp +++ b/src/coreclr/src/pal/src/safecrt/safecrt_output_l.cpp @@ -91,11 +91,6 @@ Buffer size required to be passed to _gcvt, fcvt and other fp conversion routine #define _CLDCVT _cldcvt #endif /* _CLDCVT */ -#ifdef _MBCS -#undef _MBCS -#endif /* _MBCS */ -//#include - /* this macro defines a function which is private and as fast as possible: */ /* for example, in C 6.0, it might be static _fastcall near. */ #define LOCAL(x) static x __cdecl diff --git a/src/coreclr/src/pal/src/safecrt/splitpath_s.cpp b/src/coreclr/src/pal/src/safecrt/splitpath_s.cpp index 1fe3a38..92e6636 100644 --- a/src/coreclr/src/pal/src/safecrt/splitpath_s.cpp +++ b/src/coreclr/src/pal/src/safecrt/splitpath_s.cpp @@ -25,6 +25,4 @@ #define _TCSNCPY_S strncpy_s #define _T(_Character) _Character -#define _MBS_SUPPORT 0 - #include "tsplitpath_s.inl" diff --git a/src/coreclr/src/pal/src/safecrt/tmakepath_s.inl b/src/coreclr/src/pal/src/safecrt/tmakepath_s.inl index 27d2ab7..d4b74ef 100644 --- a/src/coreclr/src/pal/src/safecrt/tmakepath_s.inl +++ b/src/coreclr/src/pal/src/safecrt/tmakepath_s.inl @@ -47,11 +47,7 @@ errno_t __cdecl _FUNC_NAME(__out_ecount_z(_SIZE) _CHAR *_DEST, __in_opt size_t _ *d++ = *p++; } while (*p != 0); -#if _MBS_SUPPORT - p = _MBSDEC(_Dir, p); -#else /* _MBS_SUPPORT */ - p = p - 1; -#endif /* _MBS_SUPPORT */ + p--; if (*p != _T('/') && *p != _T('\\')) { if(++written >= _SIZE) diff --git a/src/coreclr/src/pal/src/safecrt/tsplitpath_s.inl b/src/coreclr/src/pal/src/safecrt/tsplitpath_s.inl index 8a447c0..62b0fcf 100644 --- a/src/coreclr/src/pal/src/safecrt/tsplitpath_s.inl +++ b/src/coreclr/src/pal/src/safecrt/tsplitpath_s.inl @@ -102,26 +102,14 @@ errno_t __cdecl _FUNC_NAME( tmp = _Path; for (; *tmp != 0; ++tmp) { -#if _MBS_SUPPORT -#pragma warning(push) -#pragma warning(disable:4127) - if (_ISMBBLEAD(*tmp)) -#pragma warning(pop) + if (*tmp == _T('/') || *tmp == _T('\\')) { - tmp++; + /* point to one beyond for later copy */ + last_slash = tmp + 1; } - else -#endif /* _MBS_SUPPORT */ + else if (*tmp == _T('.')) { - if (*tmp == _T('/') || *tmp == _T('\\')) - { - /* point to one beyond for later copy */ - last_slash = tmp + 1; - } - else if (*tmp == _T('.')) - { - dot = tmp; - } + dot = tmp; } } diff --git a/src/coreclr/src/pal/src/safecrt/wmakepath_s.cpp b/src/coreclr/src/pal/src/safecrt/wmakepath_s.cpp index ab33c21..cc5445f 100644 --- a/src/coreclr/src/pal/src/safecrt/wmakepath_s.cpp +++ b/src/coreclr/src/pal/src/safecrt/wmakepath_s.cpp @@ -24,6 +24,5 @@ #define _DEST _Dst #define _SIZE _SizeInWords #define _T(_Character) L##_Character -#define _MBS_SUPPORT 0 #include "tmakepath_s.inl" diff --git a/src/coreclr/src/pal/src/safecrt/wsplitpath_s.cpp b/src/coreclr/src/pal/src/safecrt/wsplitpath_s.cpp index 6889723..420d713 100644 --- a/src/coreclr/src/pal/src/safecrt/wsplitpath_s.cpp +++ b/src/coreclr/src/pal/src/safecrt/wsplitpath_s.cpp @@ -24,6 +24,5 @@ #define _CHAR char16_t #define _TCSNCPY_S wcsncpy_s #define _T(_Character) L##_Character -#define _MBS_SUPPORT 0 #include "tsplitpath_s.inl" diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/c_runtime/CMakeLists.txt index 95aa6ac..5dab950 100644 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/CMakeLists.txt +++ b/src/coreclr/src/pal/tests/palsuite/c_runtime/CMakeLists.txt @@ -151,9 +151,6 @@ add_subdirectory(_finitef) add_subdirectory(_isnan) add_subdirectory(_isnanf) add_subdirectory(_itow) -add_subdirectory(_mbsdec) -add_subdirectory(_mbsinc) -add_subdirectory(_mbsninc) add_subdirectory(_putenv) add_subdirectory(_rotl) add_subdirectory(_rotr) diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/CMakeLists.txt deleted file mode 100644 index 91794df..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(test1) - diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt deleted file mode 100644 index 37d4768..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(SOURCES - test1.cpp -) - -add_executable(paltest_mbsdec_test1 - ${SOURCES} -) - -add_dependencies(paltest_mbsdec_test1 coreclrpal) - -target_link_libraries(paltest_mbsdec_test1 - ${COMMON_TEST_LIBRARIES} -) diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.cpp b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.cpp deleted file mode 100644 index 460f715..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: -** Ensure that this function moves the string pointer back one character. -** First do a basic test to check that the pointer gets moved back the one -** character, given str1 and str+1 as params. Then try with both -** params being the same pointer, which should return NULL. Also test -** when the first pointer is past the second pointer, which should -** return null. Finally try this function on an array of single bytes, -** which it assumes are characters and should work in the same fashion. -** -** -**==========================================================================*/ - -#include - -/* - * Note: it seems like these functions would only be useful if they - * didn't assume a character was equivalent to a single byte. Be that - * as it may, I haven't seen a way to get it to behave otherwise. - */ - -int __cdecl main(int argc, char *argv[]) -{ - unsigned char *str1 = (unsigned char*) "foo"; - unsigned char str2[] = {0xC0, 0x80, 0xC0, 0x80, 0}; - unsigned char str3[] = {0}; - unsigned char *ret = NULL; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ret = _mbsdec(str1,str1+1); - if (ret != str1) - { - Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str1); - } - - ret = _mbsdec(str1,str1); - if (ret != NULL) - { - Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, NULL); - } - - ret = _mbsdec(str1+100,str1); - if (ret != NULL) - { - Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, NULL); - } - - ret = _mbsdec(str2,str2+1); - if (ret != str2) - { - Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str2+1); - } - - ret = _mbsdec(str3,str3+10); - if (ret != str3+9) - { - Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str3+9); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/testinfo.dat b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/testinfo.dat deleted file mode 100644 index b8ac7b2..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/testinfo.dat +++ /dev/null @@ -1,17 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -Version = 1.0 -Section = C Runtime -Function = _mbsdec -Name = Positive Test for _mbsdec -TYPE = DEFAULT -EXE1 = test1 -Description -= Ensure that this function moves the string pointer back one character. -= First do a basic test to check that the pointer gets moved back the one -= character, given str1 and str+1 as params. Then try with both -= params being the same pointer, which should return NULL. Also test -= when the first pointer is past the second pointer, which should -= return null. Finally try this function on an array of single bytes, -= which it assumes are characters and should work in the same fashion. diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/CMakeLists.txt deleted file mode 100644 index 91794df..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(test1) - diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt deleted file mode 100644 index d5f7ad3..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(SOURCES - test1.cpp -) - -add_executable(paltest_mbsinc_test1 - ${SOURCES} -) - -add_dependencies(paltest_mbsinc_test1 coreclrpal) - -target_link_libraries(paltest_mbsinc_test1 - ${COMMON_TEST_LIBRARIES} -) diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.cpp b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.cpp deleted file mode 100644 index 868dfb7..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: -** Ensure that this function moves the string pointer ahead one character. -** First do a basic test to check that the pointer gets moved ahead the one -** character. Then try with an array of bytes and a NULL array. Each of -** these should still work by returning a pointer to thePointer+1. -** -** -**==========================================================================*/ - -#include - -/* - * Note: it seems like these functions would only be useful if they - * didn't assume a character was equivalent to a single byte. Be that - * as it may, I haven't seen a way to get it to behave otherwise. - */ - -int __cdecl main(int argc, char *argv[]) -{ - unsigned char *str1 = (unsigned char*) "foo"; - unsigned char str2[] = {0xC0, 0x80, 0xC0, 0x80, 0}; - unsigned char str3[] = {0}; - unsigned char *ret=NULL; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ret = _mbsinc(str1); - if (ret != str1 + 1) - { - Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); - } - - ret = _mbsinc(str2); - if (ret != str2 + 1) - { - Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); - } - - ret = _mbsinc(str3); - if (ret != str3 + 1) - { - Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/testinfo.dat b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/testinfo.dat deleted file mode 100644 index 179f668..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -Version = 1.0 -Section = C Runtime -Function = _mbsinc -Name = Positive Test for _mbsinc -TYPE = DEFAULT -EXE1 = test1 -Description -= Ensure that this function moves the string pointer ahead one character. -= First do a basic test to check that the pointer gets moved ahead the one -= character. Then try with an array of bytes and a NULL array. Each of -= these should still work by returning a pointer to thePointer+1. diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/CMakeLists.txt deleted file mode 100644 index 91794df..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(test1) - diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt deleted file mode 100644 index 523e862..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(SOURCES - test1.cpp -) - -add_executable(paltest_mbsninc_test1 - ${SOURCES} -) - -add_dependencies(paltest_mbsninc_test1 coreclrpal) - -target_link_libraries(paltest_mbsninc_test1 - ${COMMON_TEST_LIBRARIES} -) diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.cpp b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.cpp deleted file mode 100644 index 5949a55..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: -** Ensure that this functions increases a string pointer by n characters. -** Use a for loop, and increase the pointer by a different number of characters -** on each iteration, ensure that it is indeed pointing to the correct location -** each time. The second test checks to see if you attempt to increase the -** pointer past the end of the string, the pointer should just point at the -** last character. -** -** -**==========================================================================*/ - -#include - -/* - * Note: it seems like these functions would only be useful if they - * didn't assume a character was equivalent to a single byte. Be that - * as it may, I haven't seen a way to get it to behave otherwise. - */ - -int __cdecl main(int argc, char *argv[]) -{ - unsigned char str[] = {0xC0, 0x80, 0xC0, 0x80, 0}; - int i=0; - unsigned char *ret=NULL; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - for (i=0; i<5; i++) - { - ret = _mbsninc(str, i); - if (ret != str + i) - { - Fail ("ERROR: _mbsninc returned %p. Expected %p\n", ret, str+i); - } - } - - /* - * trying to advance past the end of the string should just - * return the end. - */ - ret = _mbsninc(str, 5); - if (ret != str + 4) - { - Fail ("ERROR: _mbsninc returned %p. Expected %p\n", ret, str+4); - } - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/testinfo.dat b/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/testinfo.dat deleted file mode 100644 index aea76f1..0000000 --- a/src/coreclr/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/testinfo.dat +++ /dev/null @@ -1,16 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -Version = 1.0 -Section = C Runtime -Function = _mbsninc -Name = Positive Test for _mbsninc -TYPE = DEFAULT -EXE1 = test1 -Description -= Ensure that this functions increases a string pointer by n characters. -= Use a for loop, and increase the pointer by a different number of characters -= on each iteration, ensure that it is indeed pointing to the correct location -= each time. The second test checks to see if you attempt to increase the -= pointer past the end of the string, the pointer should just point at the -= last character. diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/locale_info/CMakeLists.txt index 41cc457..1faf1db 100644 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/CMakeLists.txt +++ b/src/coreclr/src/pal/tests/palsuite/locale_info/CMakeLists.txt @@ -4,9 +4,6 @@ # add_subdirectory(GetLocaleInfoW) add_subdirectory(GetACP) -add_subdirectory(GetCPInfo) -add_subdirectory(IsDBCSLeadByte) -add_subdirectory(IsDBCSLeadByteEx) add_subdirectory(MultiByteToWideChar) add_subdirectory(WideCharToMultiByte) diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/CMakeLists.txt deleted file mode 100644 index d243b82..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -add_subdirectory(test1) -add_subdirectory(test2) -add_subdirectory(test3) - diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/CMakeLists.txt deleted file mode 100644 index 6198713..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(SOURCES - test1.cpp -) - -add_executable(paltest_getcpinfo_test1 - ${SOURCES} -) - -add_dependencies(paltest_getcpinfo_test1 coreclrpal) - -target_link_libraries(paltest_getcpinfo_test1 - ${COMMON_TEST_LIBRARIES} -) diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.cpp b/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.cpp deleted file mode 100644 index 2ef184d..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: Tests that GetCPInfo works for CP_ACP and 0x4E4 (default codepage) -** Also makes sure it correctly handles an invalid code page. -** -** -**==========================================================================*/ - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - CPINFO cpinfo; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - if (!GetCPInfo(CP_ACP, &cpinfo)) - { - Fail("GetCPInfo() unable to get info for CP_ACP\n"); - } - - if (!GetCPInfo(65001, &cpinfo)) - { - Fail("GetCPInfo() unable to get info for code page 65001 (utf8)\n"); - } - - if (GetCPInfo(-1, &cpinfo)) - { - Fail("GetCPInfo() did not error on invalid code page!\n"); - } - - if (GetLastError() != ERROR_INVALID_PARAMETER) - { - Fail("GetCPInfo() failed to set the last error to" - " ERROR_INVALID_PARAMETER!\n"); - } - - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/testinfo.dat b/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/testinfo.dat deleted file mode 100644 index a1b3007..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -Version = 1.0 -Section = Locale Information -Function = GetCPInfo -Name = Test #1 for GetCPInfo -TYPE = DEFAULT -EXE1 = test1 -Description -=Tests that GetCPInfo works for CP_ACP and 0x4E4 (default codepage) -=Also makes sure it correctly handles an invalid code page. diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/CMakeLists.txt deleted file mode 100644 index e10388a..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(SOURCES - test2.cpp -) - -add_executable(paltest_getcpinfo_test2 - ${SOURCES} -) - -add_dependencies(paltest_getcpinfo_test2 coreclrpal) - -target_link_libraries(paltest_getcpinfo_test2 - ${COMMON_TEST_LIBRARIES} -) diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/test2.cpp b/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/test2.cpp deleted file mode 100644 index 0e47d54..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/test2.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test2.c -** -** Purpose: Tests that GetCPInfo gives the correct information for codepage 0x4E4 -** (the default). -** -** -**==========================================================================*/ - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - CPINFO cpinfo; - int codepage; - unsigned int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* - * codepage 1252 (0x4E4): Windows 3.1 Latin 1 (U.S., Western Europe) - */ - codepage = 1252; - - if (!GetCPInfo(codepage, &cpinfo)) - { - Fail("GetCPInfo() failed on default ansi code page!\n"); - } - if (cpinfo.MaxCharSize != 1) - { - Fail("GetCPInfo() returned incorrect MaxCharSize information!\n"); - } - if (cpinfo.DefaultChar[0] != '?' || cpinfo.DefaultChar[1] != 0) - { - Fail("GetCPInfo() returned incorrect DefaultChar information"); - } - - for (i = 0; i - -/* Currently only one CodePage "CP_ACP" is supported by the PAL */ - -int __cdecl main(int argc, char *argv[]) -{ - CPINFO cpinfo; - - /* Initialize the PAL. - */ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Test GetCPInfo with CP_ACP. - */ - if (!GetCPInfo(CP_ACP, &cpinfo)) - { - Fail("GetCPInfo() unable to get info for code page %d!\n", CP_ACP); - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} - diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test3/testinfo.dat b/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test3/testinfo.dat deleted file mode 100644 index 13f7a29..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/GetCPInfo/test3/testinfo.dat +++ /dev/null @@ -1,8 +0,0 @@ -Version = 1.0 -Section = Locale Information -Function = GetCPInfo -Name = Test #3 for GetCPInfo -TYPE = DEFAULT -EXE1 = test3 -Description -=Tests that GetCPInfo passes for all valid code pages diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/CMakeLists.txt deleted file mode 100644 index 91794df..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(test1) - diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/CMakeLists.txt deleted file mode 100644 index afc3a30..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(SOURCES - test1.cpp -) - -add_executable(paltest_isdbcsleadbyte_test1 - ${SOURCES} -) - -add_dependencies(paltest_isdbcsleadbyte_test1 coreclrpal) - -target_link_libraries(paltest_isdbcsleadbyte_test1 - ${COMMON_TEST_LIBRARIES} -) diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.cpp b/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.cpp deleted file mode 100644 index 0d3b997..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: Tests that IsDBCSLeadByte does not find any lead-bytes in the -** current ansi code page -** -** -** TODO: Test for positive, i.e., if it is potentially isdbcsleadbyte -**==========================================================================*/ - - -#include - -void DoTest() -{ - int value; - int ret; - int i; - - - for (i=0; i<256; i++) - { - value = IsDBCSLeadByte(i); - - ret = GetLastError(); - if (ret == ERROR_INVALID_PARAMETER) - { - Fail("IsDBCSLeadByte unexpectedly errored with ERROR_INVALID_PARAMETER for %d!\n", i); - } - else if (ret != 0) - { - Fail("IsDBCSLeadByte had an unexpected error [%d] for %d!\n", ret, i); - } - else if (value) - { - Fail("IsDBCSLeadByte incorrectly found a lead byte in value [%d] for" - " %d\n", value, i); - } - - } -} - -int __cdecl main(int argc, char *argv[]) -{ - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoTest(); - - PAL_Terminate(); - -// setlocale( "japan", ); - - return PASS; -} - diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/testinfo.dat b/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/testinfo.dat deleted file mode 100644 index 5cdc938..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -Version = 1.0 -Section = Locale Information -Function = IsDBCSLeadByte -Name = Test #1 for IsDBCSLeadByte -TYPE = DEFAULT -EXE1 = test1 -Description -=Tests that IsDBCSLeadByte does not find any lead-bytes in the -=current ansi code page diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/CMakeLists.txt deleted file mode 100644 index 91794df..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(test1) - diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/CMakeLists.txt deleted file mode 100644 index b3901ca..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(SOURCES - test1.cpp -) - -add_executable(paltest_isdbcsleadbyteex_test1 - ${SOURCES} -) - -add_dependencies(paltest_isdbcsleadbyteex_test1 coreclrpal) - -target_link_libraries(paltest_isdbcsleadbyteex_test1 - ${COMMON_TEST_LIBRARIES} -) diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.cpp b/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.cpp deleted file mode 100644 index 036e2a3..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: Tests that IsDBCSLeadByteEx does not find any lead-bytes in the -** current ansi code page or the default code page. Also tests that -** it correctly handles an invalid codepage. -** -** -**==========================================================================*/ - - -#include - -void DoTest(int codepage) -{ - int value; - int ret; - int i; - - - for (i=0; i<256; i++) - { - value = IsDBCSLeadByteEx(codepage, i); - - ret = GetLastError(); - if (ret == ERROR_INVALID_PARAMETER) - { - Fail("IsDBCSLeadByteEx unexpectedly errored with ERROR_INVALID_PARAMETER!\n"); - } - else if (ret != 0) - { - Fail("IsDBCSLeadByteEx had an unexpected error!\n"); - } - else if (value) - { - Fail("IsDBCSLeadByteEx incorrectly found a lead byte in code " - "page %d\n", codepage); - } - - } -} - -int __cdecl main(int argc, char *argv[]) -{ - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - if (IsDBCSLeadByteEx(-1, 0)) - { - Fail("IsDBCSLeadByteEx did not error on an invalid code page!\n"); - } - - /* Clear the last error. */ - SetLastError(0); - - - DoTest(0); - DoTest(CP_ACP); - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/testinfo.dat b/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/testinfo.dat deleted file mode 100644 index ead792e..0000000 --- a/src/coreclr/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/testinfo.dat +++ /dev/null @@ -1,13 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -Version = 1.0 -Section = Locale Information -Function = IsDBCSLeadByteEx -Name = Test #1 for IsDBCSLeadByteEx -TYPE = DEFAULT -EXE1 = test1 -Description -=Tests that IsDBCSLeadByteEx does not find any lead-bytes in the -=current ansi code page or the default code page. Also tests that -=it correctly handles an invalid codepage. diff --git a/src/coreclr/src/pal/tests/palsuite/paltestlist.txt b/src/coreclr/src/pal/tests/palsuite/paltestlist.txt index ce633d6..9195448 100644 --- a/src/coreclr/src/pal/tests/palsuite/paltestlist.txt +++ b/src/coreclr/src/pal/tests/palsuite/paltestlist.txt @@ -348,9 +348,6 @@ c_runtime/_finitef/test1/paltest_finitef_test1 c_runtime/_isnan/test1/paltest_isnan_test1 c_runtime/_isnanf/test1/paltest_isnanf_test1 c_runtime/_itow/test1/paltest_itow_test1 -c_runtime/_mbsdec/test1/paltest_mbsdec_test1 -c_runtime/_mbsinc/test1/paltest_mbsinc_test1 -c_runtime/_mbsninc/test1/paltest_mbsninc_test1 c_runtime/_putenv/test1/paltest_putenv_test1 c_runtime/_putenv/test2/paltest_putenv_test2 c_runtime/_putenv/test3/paltest_putenv_test3 @@ -569,10 +566,6 @@ loader/LoadLibraryW/test2/paltest_loadlibraryw_test2 loader/LoadLibraryW/test3/paltest_loadlibraryw_test3 loader/LoadLibraryW/test5/paltest_loadlibraryw_test5 locale_info/GetACP/test1/paltest_getacp_test1 -locale_info/GetCPInfo/test1/paltest_getcpinfo_test1 -locale_info/GetCPInfo/test3/paltest_getcpinfo_test3 -locale_info/IsDBCSLeadByte/test1/paltest_isdbcsleadbyte_test1 -locale_info/IsDBCSLeadByteEx/test1/paltest_isdbcsleadbyteex_test1 locale_info/MultiByteToWideChar/test1/paltest_multibytetowidechar_test1 locale_info/MultiByteToWideChar/test2/paltest_multibytetowidechar_test2 locale_info/MultiByteToWideChar/test3/paltest_multibytetowidechar_test3 diff --git a/src/coreclr/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt b/src/coreclr/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt index aafef3b..dadc2cc 100644 --- a/src/coreclr/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt +++ b/src/coreclr/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt @@ -99,7 +99,6 @@ loader/LoadLibraryA/test8/paltest_loadlibrarya_test8 loader/LoadLibraryW/test1/paltest_loadlibraryw_test1 locale_info/CompareStringA/test1/paltest_comparestringa_test1 locale_info/CompareStringW/test1/paltest_comparestringw_test1 -locale_info/GetCPInfo/test2/paltest_getcpinfo_test2 locale_info/GetLocaleInfoW/test1/paltest_getlocaleinfow_test1 locale_info/GetLocaleInfoW/test2/paltest_getlocaleinfow_test2 locale_info/GetStringTypeExW/test1/paltest_getstringtypeexw_test1 diff --git a/src/coreclr/src/palrt/CMakeLists.txt b/src/coreclr/src/palrt/CMakeLists.txt index 77fdc67..a4c6fdd 100644 --- a/src/coreclr/src/palrt/CMakeLists.txt +++ b/src/coreclr/src/palrt/CMakeLists.txt @@ -8,7 +8,6 @@ set(PALRT_SOURCES guid.cpp memorystream.cpp path.cpp - unicode.cpp variant.cpp ) diff --git a/src/coreclr/src/palrt/unicode.cpp b/src/coreclr/src/palrt/unicode.cpp deleted file mode 100644 index 9def01d..0000000 --- a/src/coreclr/src/palrt/unicode.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -#include "common.h" - -// This is a simplified implementation of IsTextUnicode. -// https://github.com/dotnet/runtime/issues/4778 -BOOL IsTextUnicode(CONST VOID* lpv, int iSize, LPINT lpiResult) -{ - *lpiResult = 0; - - if (iSize < 2) return FALSE; - - BYTE * p = (BYTE *)lpv; - - // Check for Unicode BOM - if ((*p == 0xFF) && (*(p+1) == 0xFE)) - { - *lpiResult |= IS_TEXT_UNICODE_SIGNATURE; - return TRUE; - } - - return FALSE; -} - diff --git a/src/coreclr/src/utilcode/makepath.cpp b/src/coreclr/src/utilcode/makepath.cpp index 9391447..374cda4 100644 --- a/src/coreclr/src/utilcode/makepath.cpp +++ b/src/coreclr/src/utilcode/makepath.cpp @@ -100,16 +100,12 @@ void MakePath ( _ASSERTE(count < maxCount); } -#ifdef _MBCS - if (*(p=_mbsdec(dir,p)) != _T('/') && *p != _T('\\')) { -#else /* _MBCS */ // suppress warning for the following line; this is safe but would require significant code // delta for prefast to understand. #ifdef _PREFAST_ #pragma warning( suppress: 26001 ) #endif if (*(p-1) != _T('/') && *(p-1) != _T('\\')) { -#endif /* _MBCS */ *path++ = _T('\\'); count++; diff --git a/src/coreclr/src/utilcode/splitpath.cpp b/src/coreclr/src/utilcode/splitpath.cpp index 9e56b6b..56e4a8d 100644 --- a/src/coreclr/src/utilcode/splitpath.cpp +++ b/src/coreclr/src/utilcode/splitpath.cpp @@ -144,19 +144,11 @@ void SplitPathInterior( */ for (last_slash = NULL, p = (WCHAR *)wszPath; *p; p++) { -#ifdef _MBCS - if (_ISLEADBYTE (*p)) - p++; - else { -#endif /* _MBCS */ if (*p == _T('/') || *p == _T('\\')) /* point to one beyond for later copy */ last_slash = p + 1; else if (*p == _T('.')) dot = p; -#ifdef _MBCS - } -#endif /* _MBCS */ } if (last_slash) { diff --git a/src/coreclr/src/utilcode/sstring.cpp b/src/coreclr/src/utilcode/sstring.cpp index 1647a9e..9ac89bc 100644 --- a/src/coreclr/src/utilcode/sstring.cpp +++ b/src/coreclr/src/utilcode/sstring.cpp @@ -155,34 +155,6 @@ int SString::CaseCompareHelper(const WCHAR *buffer1, const WCHAR *buffer2, COUNT #define CAN_SIMPLE_UPCASE_ANSI(x) (((x) >= 0x20) && ((x) <= 0x7f)) #define SIMPLE_UPCASE_ANSI(x) (IS_LOWER_A_TO_Z(x) ? ((x) - 'a' + 'A') : (x)) -int GetCaseInsensitiveValueA(const CHAR *buffer, int length) { - LIMITED_METHOD_CONTRACT; - _ASSERTE(buffer != NULL); - _ASSERTE(length == 1 || ((length == 2) && IsDBCSLeadByte(*buffer))); - - WCHAR wideCh; - int sortValue; - int conversionReturn = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, length, &wideCh, 1); - if (conversionReturn == 0) - { - // An invalid sequence should only compare equal to itself, so use a negative mapping. - if (length == 1) - { - sortValue = -((int)((unsigned char)(*buffer))); - } - else - { - sortValue = -(((((int)((unsigned char)(*buffer))) << 8) | ((int)((unsigned char)(*(buffer + 1)))))); - } - } - else - { - _ASSERTE(conversionReturn == 1); - sortValue = MapChar(wideCh, LCMAP_UPPERCASE); - } - return sortValue; -} - /* static */ int SString::CaseCompareHelperA(const CHAR *buffer1, const CHAR *buffer2, COUNT_T count, BOOL stopOnNull, BOOL stopOnCount) { @@ -197,49 +169,21 @@ int SString::CaseCompareHelperA(const CHAR *buffer1, const CHAR *buffer2, COUNT_ { CHAR ch1 = *buffer1; CHAR ch2 = *buffer2; - if ((ch1 == 0) || (ch2 == 0)) + diff = ch1 - ch2; + if (diff != 0 || stopOnNull) { - diff = ch1 - ch2; - if (diff != 0 || stopOnNull) + if (ch1 == 0 || ch2 == 0) { break; } - buffer1++; - buffer2++; - } - else if (CAN_SIMPLE_UPCASE_ANSI(ch1) && CAN_SIMPLE_UPCASE_ANSI(ch2)) - { - diff = ch1 - ch2; - if (diff != 0) - { - diff = (SIMPLE_UPCASE_ANSI(ch1) - SIMPLE_UPCASE_ANSI(ch2)); - if (diff != 0) - { - break; - } - } - buffer1++; - buffer2++; - } - else - { - int length = 1; - if (IsDBCSLeadByte(ch1) - && IsDBCSLeadByte(ch2) - && (!stopOnCount || ((buffer1 + 1) < buffer1End))) - { - length = 2; - } - int sortValue1 = GetCaseInsensitiveValueA(buffer1, length); - int sortValue2 = GetCaseInsensitiveValueA(buffer2, length); - diff = sortValue1 - sortValue2; + diff = (SIMPLE_UPCASE_ANSI(ch1) - SIMPLE_UPCASE_ANSI(ch2)); if (diff != 0) { break; } - buffer1 += length; - buffer2 += length; } + buffer1++; + buffer2++; } return diff; } @@ -1517,11 +1461,11 @@ int SString::CompareCaseInsensitive(const SString &s) const switch (GetRepresentation()) { case REPRESENTATION_UNICODE: + case REPRESENTATION_ANSI: result = CaseCompareHelper(GetRawUnicode(), source.GetRawUnicode(), smaller, FALSE, TRUE); break; case REPRESENTATION_ASCII: - case REPRESENTATION_ANSI: result = CaseCompareHelperA(GetRawASCII(), source.GetRawASCII(), smaller, FALSE, TRUE); break; @@ -1612,10 +1556,10 @@ BOOL SString::EqualsCaseInsensitive(const SString &s) const switch (GetRepresentation()) { case REPRESENTATION_UNICODE: + case REPRESENTATION_ANSI: RETURN (CaseCompareHelper(GetRawUnicode(), source.GetRawUnicode(), count, FALSE, TRUE) == 0); case REPRESENTATION_ASCII: - case REPRESENTATION_ANSI: RETURN (CaseCompareHelperA(GetRawASCII(), source.GetRawASCII(), count, FALSE, TRUE) == 0); case REPRESENTATION_EMPTY: -- 2.7.4