diff --git a/pal/src/CMakeLists.txt b/pal/src/CMakeLists.txt index 8bd9fc75426..be34796d681 100644 --- a/pal/src/CMakeLists.txt +++ b/pal/src/CMakeLists.txt @@ -93,9 +93,8 @@ set(SOURCES cruntime/wchar.cpp cruntime/wchartls.cpp safecrt/makepath_s.c - safecrt/mbusafecrt.c + safecrt/mbusafecrt.c safecrt/safecrt_input_s.c -# safecrt/safecrt_output_l.c safecrt/safecrt_output_s.c safecrt/safecrt_winput_s.c safecrt/safecrt_woutput_s.c @@ -181,7 +180,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux) unwind-x86_64 ) endif() - + target_link_libraries(Chakra.Pal gcc_s pthread diff --git a/pal/src/cruntime/printf.cpp b/pal/src/cruntime/printf.cpp index 9b3407428a9..9e4f03e1a14 100644 --- a/pal/src/cruntime/printf.cpp +++ b/pal/src/cruntime/printf.cpp @@ -1,6 +1,6 @@ // // Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. // /*++ @@ -69,8 +69,8 @@ BOOL Internal_AddPaddingA(LPSTR *Out, INT Count, LPSTR In, INT PaddingOriginal = Padding; INT LengthInStr; LengthInStr = strlen(In); - - + + if (Padding < 0) { /* this is used at the bottom to determine if the buffer ran out */ @@ -322,7 +322,7 @@ wsprintfW( PERF_ENTRY(wsprintfW); ENTRY("wsprintfW (buffer=%p, format=%p (%S))\n", buffer, format, format); - + va_start(ap, format); Length = PAL__wvsnprintf(buffer, 1024, format, ap); va_end(ap); @@ -361,7 +361,7 @@ _snprintf( LOGEXIT("_snprintf returns int %d\n", Length); PERF_EXIT(_snprintf); return Length; -} +} /*++ @@ -616,7 +616,7 @@ static BOOL Internal_ScanfExtractFormatA(LPCSTR *Fmt, LPSTR Out, int iOutSize, L else if (*Prefix == SCANF_PREFIX_LONGLONG) { CHECK_OUT_IN_ITS_RANGE(Out,BaseOut,EndOut) - + if (strcpy_s(Out, iOutSize-(Out-BaseOut), scanf_longlongfmt) != SAFECRT_SUCCESS) { ERROR("strcpy_s failed\n"); @@ -657,7 +657,7 @@ static BOOL Internal_ScanfExtractFormatA(LPCSTR *Fmt, LPSTR Out, int iOutSize, L { /* There is a small compatibility problem in the handling of the [] option in FreeBSD vs. Windows. In Windows, you can have [z-a] - as well as [a-z]. In FreeBSD, [z-a] fails. So, we need to + as well as [a-z]. In FreeBSD, [z-a] fails. So, we need to reverse the instances of z-a to a-z (and [m-e] to [e-m], etc). */ /* step 1 : copy the leading [ */ @@ -673,8 +673,8 @@ static BOOL Internal_ScanfExtractFormatA(LPCSTR *Fmt, LPSTR Out, int iOutSize, L (*Fmt)++; } - /* step 3 : copy a leading ], if present; a ] immediately after the - leading [ (or [^) does *not* end the sequence, it is part of the + /* step 3 : copy a leading ], if present; a ] immediately after the + leading [ (or [^) does *not* end the sequence, it is part of the characters to match */ if( ']' == **Fmt ) { @@ -683,7 +683,7 @@ static BOOL Internal_ScanfExtractFormatA(LPCSTR *Fmt, LPSTR Out, int iOutSize, L (*Fmt)++; } - /* step 4 : if the next character is already a '-', it's not part of an + /* step 4 : if the next character is already a '-', it's not part of an interval specifier, so just copy it */ if('-' == **Fmt ) { @@ -693,7 +693,7 @@ static BOOL Internal_ScanfExtractFormatA(LPCSTR *Fmt, LPSTR Out, int iOutSize, L } /* ok then, process the rest of it */ - while( '\0' != **Fmt ) + while( '\0' != **Fmt ) { if(']' == **Fmt) { @@ -707,7 +707,7 @@ static BOOL Internal_ScanfExtractFormatA(LPCSTR *Fmt, LPSTR Out, int iOutSize, L { if( ']' == (*Fmt)[1] ) { - /* got a '-', next character is the terminating ']'; + /* got a '-', next character is the terminating ']'; copy '-' literally */ CHECK_OUT_IN_ITS_RANGE(Out,BaseOut,EndOut) *Out++ = '-'; @@ -722,14 +722,14 @@ static BOOL Internal_ScanfExtractFormatA(LPCSTR *Fmt, LPSTR Out, int iOutSize, L prev = (*Fmt)[-1]; next = (*Fmt)[1]; - /* if boundaries were inverted, replace the already-copied + /* if boundaries were inverted, replace the already-copied low boundary by the 'real' low boundary */ if( prev > next ) { CHECK_OUT_IN_ITS_RANGE(Out-1,BaseOut,EndOut) Out[-1] = next; - /* ...and save the 'real' upper boundary, which will be + /* ...and save the 'real' upper boundary, which will be copied to 'Out' below */ next = prev; } @@ -739,7 +739,7 @@ static BOOL Internal_ScanfExtractFormatA(LPCSTR *Fmt, LPSTR Out, int iOutSize, L CHECK_OUT_IN_ITS_RANGE(Out,BaseOut,EndOut) *Out++ = next; - /* skip over the '-' and the next character, which we + /* skip over the '-' and the next character, which we already copied */ (*Fmt)+=2; } @@ -750,7 +750,7 @@ static BOOL Internal_ScanfExtractFormatA(LPCSTR *Fmt, LPSTR Out, int iOutSize, L CHECK_OUT_IN_ITS_RANGE(Out,BaseOut,EndOut) *Out++ = **Fmt; (*Fmt)++; - } + } } *Type = SCANF_TYPE_BRACKETS; @@ -760,7 +760,7 @@ static BOOL Internal_ScanfExtractFormatA(LPCSTR *Fmt, LPSTR Out, int iOutSize, L { *Type = SCANF_TYPE_SPACE; } - + /* add %n so we know how far to increment the pointer */ CHECK_OUT_IN_ITS_RANGE(Out,BaseOut,EndOut) *Out++ = '%'; @@ -961,7 +961,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize, { /* There is a small compatibility problem in the handling of the [] option in FreeBSD vs. Windows. In Windows, you can have [z-a] - as well as [a-z]. In FreeBSD, [z-a] fails. So, we need to + as well as [a-z]. In FreeBSD, [z-a] fails. So, we need to reverse the instances of z-a to a-z (and [m-e] to [e-m], etc). */ /* step 1 : copy the leading [ */ @@ -975,8 +975,8 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize, (*Fmt)++; } - /* step 3 : copy a leading ], if present; a ] immediately after the - leading [ (or [^) does *not* end the sequence, it is part of the + /* step 3 : copy a leading ], if present; a ] immediately after the + leading [ (or [^) does *not* end the sequence, it is part of the characters to match */ if( ']' == **Fmt ) { @@ -984,7 +984,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize, (*Fmt)++; } - /* step 4 : if the next character is already a '-', it's not part of an + /* step 4 : if the next character is already a '-', it's not part of an interval specifier, so just copy it */ if('-' == **Fmt ) { @@ -993,7 +993,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize, } /* ok then, process the rest of it */ - while( '\0' != **Fmt ) + while( '\0' != **Fmt ) { if(']' == **Fmt) { @@ -1006,7 +1006,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize, { if( ']' == (*Fmt)[1] ) { - /* got a '-', next character is the terminating ']'; + /* got a '-', next character is the terminating ']'; copy '-' literally */ *Out++ = '-'; (*Fmt)++; @@ -1020,13 +1020,13 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize, prev = (*Fmt)[-1]; next = (*Fmt)[1]; - /* if boundaries were inverted, replace the already-copied + /* if boundaries were inverted, replace the already-copied low boundary by the 'real' low boundary */ if( prev > next ) { Out[-1] = next; - /* ...and save the 'real' upper boundary, which will be + /* ...and save the 'real' upper boundary, which will be copied to 'Out' below */ next = prev; } @@ -1034,7 +1034,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize, *Out++ = '-'; *Out++ = next; - /* skip over the '-' and the next character, which we + /* skip over the '-' and the next character, which we already copied */ (*Fmt)+=2; } @@ -1044,7 +1044,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize, /* plain character; just copy it */ *Out++ = **Fmt; (*Fmt)++; - } + } } *Type = SCANF_TYPE_BRACKETS; @@ -1181,7 +1181,7 @@ int PAL_vsscanf(LPCSTR Buffer, LPCSTR Format, va_list ap) // Since this is not a Safe CRT API we don’t really know the size of the destination // buffer provided by the caller. So we have to assume that the caller has allocated // enough space to hold either the width specified in the format or the entire input - // string plus ‘\0’. + // string plus ‘\0’. typeLen = ((Width > 0) ? Width : strlen(Buffer)) + 1; } else if (Type == SCANF_TYPE_CHAR) @@ -1240,7 +1240,7 @@ int PAL_vsscanf(LPCSTR Buffer, LPCSTR Format, va_list ap) } } } - + return Length; } @@ -1362,7 +1362,7 @@ int PAL_wvsscanf(LPCWSTR Buffer, LPCWSTR Format, va_list ap) { ASSERT("WideCharToMultiByte failed. Error is %d\n", GetLastError()); - PAL_free(newBuff); + PAL_free(newBuff); return -1; } @@ -1384,16 +1384,16 @@ int PAL_wvsscanf(LPCWSTR Buffer, LPCWSTR Format, va_list ap) TempBuff[0] = '%'; TempBuff[1] = '*'; - /* %n doesn't count as a conversion. Since we're - suppressing conversion of the %[], sscanf will - always return 0, so we can't use the return value - to determine success. Set n to 0 before the call; if + /* %n doesn't count as a conversion. Since we're + suppressing conversion of the %[], sscanf will + always return 0, so we can't use the return value + to determine success. Set n to 0 before the call; if it's still 0 afterwards, we know the call failed */ n = 0; sscanf_s(newBuff, TempBuff, &n); if(0 == n) { - /* sscanf failed, nothing matched. set ret to 0, + /* sscanf failed, nothing matched. set ret to 0, so we know we have to break */ ret = 0; } @@ -1419,7 +1419,7 @@ int PAL_wvsscanf(LPCWSTR Buffer, LPCWSTR Format, va_list ap) // We don’t really know the size of the destination buffer provided by the // caller. So we have to assume that the caller has allocated enough space // to hold either the width specified in the format or the entire input - // string plus ‘\0’. + // string plus ‘\0’. typeLen = ((Width > 0) ? Width : PAL_wcslen(Buffer)) + 1; } else if (Type == SCANF_TYPE_CHAR) @@ -1449,7 +1449,7 @@ int PAL_wvsscanf(LPCWSTR Buffer, LPCWSTR Format, va_list ap) ret = SscanfFloatCheckExponent(newBuff, TempBuff, voidPtr, &n); } #endif // SSCANF_CANNOT_HANDLE_MISSING_EXPONENT - + PAL_free(newBuff); if (ret > 0) { @@ -1478,7 +1478,7 @@ int PAL_wvsscanf(LPCWSTR Buffer, LPCWSTR Format, va_list ap) } } } - + return Length; } @@ -1557,7 +1557,7 @@ PAL_swprintf( PERF_ENTRY(swprintf); ENTRY("PAL_swprintf (buffer=%p, format=%p (%S))\n", buffer, format, format); - + va_start(ap, format); Length = PAL__wvsnprintf(buffer, 0x7fffffff, format, ap); va_end(ap); @@ -1602,16 +1602,16 @@ PAL_swscanf( See MSDN doc. --*/ -int -__cdecl -PAL_vsprintf(char *buffer, - const char *format, +int +__cdecl +PAL_vsprintf(char *buffer, + const char *format, va_list argptr) { LONG Length; PERF_ENTRY(vsprintf); - ENTRY("PAL_vsprintf (buffer=%p, format=%p (%s), argptr=%p)\n", + ENTRY("PAL_vsprintf (buffer=%p, format=%p (%s), argptr=%p)\n", buffer, format, format, argptr); Length = PAL__vsnprintf(buffer, 0x7fffffff, format, argptr); @@ -1629,17 +1629,17 @@ PAL_vsprintf(char *buffer, See MSDN doc. --*/ -int -__cdecl -_vsnprintf(char *buffer, - size_t count, - const char *format, +int +__cdecl +_vsnprintf(char *buffer, + size_t count, + const char *format, va_list argptr) { LONG Length; PERF_ENTRY(_vsnprintf); - ENTRY("_vsnprintf (buffer=%p, count=%d, format=%p (%s), argptr=%p)\n", + ENTRY("_vsnprintf (buffer=%p, count=%d, format=%p (%s), argptr=%p)\n", buffer, count, format, format, argptr); Length = PAL__vsnprintf(buffer, count, format, argptr); @@ -1658,16 +1658,16 @@ _vsnprintf(char *buffer, See MSDN doc. --*/ -int -__cdecl -PAL_vswprintf(char16_t *buffer, - const char16_t *format, +int +__cdecl +PAL_vswprintf(char16_t *buffer, + const char16_t *format, va_list argptr) { LONG Length; PERF_ENTRY(vswprintf); - ENTRY("PAL_vswprintf (buffer=%p, format=%p (%S), argptr=%p)\n", + ENTRY("PAL_vswprintf (buffer=%p, format=%p (%S), argptr=%p)\n", buffer, format, format, argptr); Length = PAL__wvsnprintf(buffer, 0x7fffffff, format, argptr); @@ -1685,19 +1685,19 @@ PAL_vswprintf(char16_t *buffer, See MSDN doc. --*/ -int -__cdecl -_vsnwprintf(char16_t *buffer, - size_t count, - const char16_t *format, +int +__cdecl +_vsnwprintf(char16_t *buffer, + size_t count, + const char16_t *format, va_list argptr) { LONG Length; PERF_ENTRY(_vsnwprintf); - ENTRY("_vsnwprintf (buffer=%p, count=%lu, format=%p (%S), argptr=%p)\n", + ENTRY("_vsnwprintf (buffer=%p, count=%lu, format=%p (%S), argptr=%p)\n", buffer, (unsigned long) count, format, format, argptr); - + Length = PAL__wvsnprintf(buffer, count, format, argptr); LOGEXIT("_vsnwprintf returns int %d\n", Length); @@ -1712,21 +1712,21 @@ _vsnwprintf(char16_t *buffer, SscanfFloatCheckExponent Parameters: - buff: pointer to the buffer to be parsed; the target float must be at - the beginning of the buffer, except for any number of leading + buff: pointer to the buffer to be parsed; the target float must be at + the beginning of the buffer, except for any number of leading spaces floatFmt: must be "%e%n" (or "%f%n" or "%g%n") voidptr: optional pointer to output variable (which should be a float) pn: pointer to an int to receive the number of bytes parsed. - + Notes: - On some platforms (specifically AIX) sscanf fails to parse a float from - a string such as 12.34e (while it succeeds for e.g. 12.34a). Sscanf - initially interprets the 'e' as the keyword for the beginning of a - 10-exponent of a floating point in scientific notation (as in 12.34e5), - but then it fails to parse the actual exponent. At this point sscanf should - be able to fall back on the narrower pattern, and parse the floating point - in common decimal notation (i.e. 12.34). However AIX's sscanf fails to do + On some platforms (specifically AIX) sscanf fails to parse a float from + a string such as 12.34e (while it succeeds for e.g. 12.34a). Sscanf + initially interprets the 'e' as the keyword for the beginning of a + 10-exponent of a floating point in scientific notation (as in 12.34e5), + but then it fails to parse the actual exponent. At this point sscanf should + be able to fall back on the narrower pattern, and parse the floating point + in common decimal notation (i.e. 12.34). However AIX's sscanf fails to do so and it does not parse any number. This function checks the given string for a such case and removes the 'e' before parsing the float. @@ -1761,11 +1761,11 @@ static int SscanfFloatCheckExponent(LPCSTR buff, LPCSTR floatFmt, pos++; } - /* check if it is something like 12.34e and the trailing 'e' is not + /* check if it is something like 12.34e and the trailing 'e' is not the suffix of a valid exponent of 10, such as 12.34e+5 */ if ( digits > 0 && *pos && tolower(*pos) == 'e' && - !( *(pos+1) && - ( isdigit(*(pos+1)) || + !( *(pos+1) && + ( isdigit(*(pos+1)) || ( (*(pos+1) == '+' || *(pos+1) == '-') && isdigit(*(pos+2)) ) ) ) @@ -1775,7 +1775,7 @@ static int SscanfFloatCheckExponent(LPCSTR buff, LPCSTR floatFmt, if (pLocBuf) { memcpy(pLocBuf, buff, (pos-buff)*sizeof(CHAR)); - pLocBuf[pos-buff] = 0; + pLocBuf[pos-buff] = 0; if (voidPtr) ret = sscanf_s(pLocBuf, floatFmt, voidPtr, pn); else @@ -1786,4 +1786,3 @@ static int SscanfFloatCheckExponent(LPCSTR buff, LPCSTR floatFmt, return ret; } #endif // SSCANF_CANNOT_HANDLE_MISSING_EXPONENT - diff --git a/pal/src/cruntime/printfcpp.cpp b/pal/src/cruntime/printfcpp.cpp index 11c5af6edbc..477d6d6c4aa 100644 --- a/pal/src/cruntime/printfcpp.cpp +++ b/pal/src/cruntime/printfcpp.cpp @@ -1,6 +1,6 @@ // // Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. // /*++ @@ -322,13 +322,13 @@ BOOL Internal_ExtractFormatA(CPalThread *pthrCurrent, LPCSTR *Fmt, LPSTR Out, LP #ifdef BIT64 // Only want to change the prefix on 64 bit when printing characters. if (**Fmt == 'c' || **Fmt == 's') -#endif +#endif { *Prefix = PFF_PREFIX_LONG; } if (**Fmt == 'l') { - *Prefix = PFF_PREFIX_LONGLONG; + *Prefix = PFF_PREFIX_LONGLONG; ++(*Fmt); } } @@ -625,7 +625,7 @@ BOOL Internal_ExtractFormatW(CPalThread *pthrCurrent, LPCWSTR *Fmt, LPSTR Out, L #ifdef BIT64 // Only want to change the prefix on 64 bit when printing characters. if (**Fmt == 'C' || **Fmt == 'S') -#endif +#endif { *Prefix = PFF_PREFIX_LONG_W; } @@ -797,7 +797,7 @@ BOOL Internal_AddPaddingW(LPWSTR *Out, INT Count, LPWSTR In, INT Padding, INT Fl INT PaddingOriginal = Padding; INT LengthInStr; LengthInStr = PAL_wcslen(In); - + if (Padding < 0) { @@ -940,7 +940,7 @@ INT Internal_AddPaddingVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, LPSTR #if FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL clearerr (stream->bsdFilePtr); #endif - + Written = InternalFwrite(OutOriginal, 1, Length, stream->bsdFilePtr, &stream->PALferrorCode); if (stream->PALferrorCode == PAL_FILE_ERROR) { @@ -1039,7 +1039,7 @@ static INT Internal_AddPaddingVfwprintf(CPalThread *pthrCurrent, PAL_FILE *strea } if (Length > 0) { - Written = Internal_Convertfwrite(pthrCurrent, OutOriginal, sizeof(char16_t), Length, + Written = Internal_Convertfwrite(pthrCurrent, OutOriginal, sizeof(char16_t), Length, (FILE*)(stream->bsdFilePtr), convert); if (-1 == Written) @@ -1169,7 +1169,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char16_t *for PERF_ENTRY(vfwprintf); ENTRY("vfwprintf (stream=%p, format=%p (%S))\n", stream, format, format); - + va_copy(ap, aparg); while (*Fmt) @@ -1404,9 +1404,9 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char16_t *for trunc1 = va_arg(ap, LONG); trunc2 = (short)trunc1; trunc1 = trunc2; - + TempInt = snprintf(TempSprintfStr, TEMP_COUNT, TempBuff, trunc1); - + if (TempInt < 0 || static_cast(TempInt) >= TEMP_COUNT) { if (NULL == (TempSprintfStrPtr = (char*)InternalMalloc(++TempInt))) @@ -1418,7 +1418,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char16_t *for va_end(ap); return -1; } - + TempSprintfStr = TempSprintfStrPtr; snprintf(TempSprintfStr, TempInt, TempBuff, trunc2); } @@ -1446,7 +1446,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char16_t *for va_end(ap); return -1; } - + TempSprintfStr = TempSprintfStrPtr; snprintf(TempSprintfStr, TempInt, TempBuff, s); } @@ -1471,7 +1471,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char16_t *for va_end(ap); return -1; } - + TempSprintfStr = TempSprintfStrPtr; va_copy(apcopy, ap); vsnprintf(TempSprintfStr, TempInt, TempBuff, apcopy); @@ -1483,7 +1483,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char16_t *for mbtowcResult = MultiByteToWideChar(CP_ACP, 0, TempSprintfStr, -1, NULL, 0); - + if (mbtowcResult == 0) { ERROR("MultiByteToWideChar failed\n"); @@ -1514,12 +1514,12 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char16_t *for MultiByteToWideChar(CP_ACP, 0, TempSprintfStr, -1, TempWideBuffer, mbtowcResult); - + ret = Internal_Convertfwrite( - pthrCurrent, - TempWideBuffer, - sizeof(char16_t), - mbtowcResult-1, + pthrCurrent, + TempWideBuffer, + sizeof(char16_t), + mbtowcResult-1, (FILE*)stream->bsdFilePtr, textMode); @@ -1546,13 +1546,13 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char16_t *for else { ret = Internal_Convertfwrite( - pthrCurrent, - Fmt++, - sizeof(char16_t), - 1, + pthrCurrent, + Fmt++, + sizeof(char16_t), + 1, (FILE*)stream->bsdFilePtr, textMode); /* copy regular chars into buffer */ - + if (-1 == ret) { ERROR("fwrite() failed with errno == %d\n", errno); @@ -1589,7 +1589,7 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo INT TempInt; int wctombResult; va_list ap; - + va_copy(ap, aparg); while (*Fmt) @@ -1630,7 +1630,7 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo Length = WideCharToMultiByte(CP_ACP, 0, TempWStr, -1, 0, 0, 0, 0); if (!Length) - { + { ASSERT("WideCharToMultiByte failed. Error is %d\n", GetLastError()); va_end(ap); @@ -1638,7 +1638,7 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo } TempStr = (LPSTR) InternalMalloc(Length); if (!TempStr) - { + { ERROR("InternalMalloc failed\n"); pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY); va_end(ap); @@ -1672,7 +1672,7 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo wctombResult = WideCharToMultiByte(CP_ACP, 0, TempWStr, -1, TempStr, Length, 0, 0); if (!wctombResult) - { + { ASSERT("WideCharToMultiByte failed. Error is %d\n", GetLastError()); InternalFree(TempStr); @@ -1713,7 +1713,7 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo TempBuffer, sizeof(TempBuffer), 0, 0); if (!Length) - { + { ASSERT("WideCharToMultiByte failed. Error is %d\n", GetLastError()); va_end(ap); @@ -1888,8 +1888,9 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR PERF_ENTRY(wvsnprintf); ENTRY("wvsnprintf (buffer=%p, count=%u, format=%p (%S))\n", Buffer, Count, Format, Format); - + va_copy(ap, aparg); + BOOL precisionSet = false; while (*Fmt) { @@ -1907,7 +1908,7 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR (Type == PFF_TYPE_STRING || Type == PFF_TYPE_WSTRING)) || (Prefix == PFF_PREFIX_SHORT && Type == PFF_TYPE_STRING) || (Type == PFF_TYPE_WSTRING && (Flags & PFF_ZERO) != 0)) - { + { BOOL needToFree = FALSE; if (WIDTH_STAR == Width) @@ -1923,6 +1924,7 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR if (PRECISION_STAR == Precision) { Precision = va_arg(ap, INT); + precisionSet = true; } else if (PRECISION_INVALID == Precision) { @@ -1952,23 +1954,31 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR TempWStr, Length ); } else - { + { ERROR( "InternalMalloc failed.\n" ); va_end(ap); return -1; } } else - { + { ASSERT( "Unable to convert from multibyte " - " to wide char.\n" ); + " to wide char.\n" ); va_end(ap); return -1; } + } + INT Length = 0; + if (precisionSet) + { + for(; Length <= Precision && TempWStr[Length] != 0; Length++); } - - INT Length = PAL_wcslen(TempWStr); + else + { + Length = PAL_wcslen(TempWStr); + } + WorkingWStr = (LPWSTR) InternalMalloc(sizeof(WCHAR) * (Length + 1)); if (!WorkingWStr) { @@ -1989,7 +1999,7 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR } else if (Precision > 0 && Precision < Length) { - if (wcsncpy_s(WorkingWStr, (Length + 1), TempWStr, Precision+1) != SAFECRT_SUCCESS) + if (wcsncpy_s(WorkingWStr, (Length + 1), TempWStr, Precision) != SAFECRT_SUCCESS) { ERROR("CoreWvsnprintf failed\n"); if (needToFree) @@ -2002,7 +2012,6 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR va_end(ap); return (-1); } - Length = Precision; } else @@ -2145,7 +2154,7 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR va_end(ap); return -1; } - + if (strncpy_s(TempNumberBuffer, TempCount+1, (LPSTR) BufferPtr, TempCount) != SAFECRT_SUCCESS) { ASSERT("strncpy_s failed!\n"); @@ -2159,7 +2168,7 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR TempCount, BufferPtr, TempCount); if (!mbtowcResult) - { + { ASSERT("MultiByteToWideChar failed. Error is %d\n", GetLastError()); InternalFree(TempNumberBuffer); @@ -2173,17 +2182,17 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR { TempNumberBuffer = (LPSTR) InternalMalloc(TempInt+1); if (!TempNumberBuffer) - { + { ERROR("InternalMalloc failed\n"); pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY); va_end(ap); return -1; } - + if (strncpy_s(TempNumberBuffer, TempInt+1, (LPSTR) BufferPtr, TempInt) != SAFECRT_SUCCESS) { ASSERT("strncpy_s failed!\n"); - InternalFree(TempNumberBuffer); + InternalFree(TempNumberBuffer); va_end(ap); return -1; } @@ -2193,10 +2202,10 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR TempInt, BufferPtr, TempInt); if (!mbtowcResult) - { + { ASSERT("MultiByteToWideChar failed. Error is %d\n", GetLastError()); - InternalFree(TempNumberBuffer); + InternalFree(TempNumberBuffer); va_end(ap); return -1; } @@ -2215,7 +2224,7 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR { *BufferPtr = 0; /* end the string */ } - + va_end(ap); if (BufferRanOut) @@ -2247,11 +2256,11 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, int written = 0; int paddingReturnValue; va_list ap; - + PERF_ENTRY(vfprintf); - + va_copy(ap, aparg); - + while (*Fmt) { if (*Fmt == '%' && @@ -2297,7 +2306,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, { ERROR("InternalMalloc failed\n"); pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY); - PERF_EXIT(vfprintf); + PERF_EXIT(vfprintf); va_end(ap); return -1; } @@ -2349,7 +2358,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, { ERROR("Internal_AddPaddingVfprintf failed\n"); InternalFree(TempStr); - PERF_EXIT(vfprintf); + PERF_EXIT(vfprintf); va_end(ap); return -1; } @@ -2372,7 +2381,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, /* ignore (because it's a char), and remove arg */ TempInt = va_arg(ap, INT); /* value not used */ } - + TempWChar = va_arg(ap, int); Length = WideCharToMultiByte(CP_ACP, 0, &TempWChar, 1, TempBuffer, sizeof(TempBuffer), @@ -2433,7 +2442,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, ch[1] = '\0'; Length = 1; paddingReturnValue = Internal_AddPaddingVfprintf( - pthrCurrent, + pthrCurrent, stream, ch, Width - Length, @@ -2464,7 +2473,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, if (-1 == paddingReturnValue) { ERROR("Internal_AddPaddingVfprintf failed\n"); - PERF_EXIT(vfprintf); + PERF_EXIT(vfprintf); va_end(ap); return -1; } @@ -2531,7 +2540,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, if (stream->PALferrorCode == PAL_FILE_ERROR) { ERROR("fwrite() failed with errno == %d\n", errno); - PERF_EXIT(vfprintf); + PERF_EXIT(vfprintf); va_end(ap); return -1; } diff --git a/pal/src/safecrt/mbusafecrt_internal.h b/pal/src/safecrt/mbusafecrt_internal.h index 1f114e43ced..c2f267b2ac8 100644 --- a/pal/src/safecrt/mbusafecrt_internal.h +++ b/pal/src/safecrt/mbusafecrt_internal.h @@ -1,6 +1,6 @@ // // Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. // /*** diff --git a/pal/src/safecrt/safecrt_output_l.c b/pal/src/safecrt/safecrt_output_l.c deleted file mode 100644 index 50d0bb678b6..00000000000 --- a/pal/src/safecrt/safecrt_output_l.c +++ /dev/null @@ -1,1629 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*** -*safecrt_output_l.c - implementation of the _output family for safercrt.lib -* - -* -*Purpose: -* This file contains the implementation of the _output family for safercrt.lib. -* -*Revision History: -* 07-08-04 SJ Stub module created. -* 07-13-04 AC Added support for floating-point types. -* 07-29-04 AC Added macros for a safecrt version of mctowc and wctomb, which target ntdll.dll or msvcrt.dll -* based on the _NTSUBSET_ #define -* 09-24-04 MSL Prefix disallow NULL deref -* -****/ - -#define _SAFECRT_IMPL - -#define __STDC_LIMIT_MACROS -#include "pal/palinternal.h" -#include -#include -#include -#include -#include "internal_securecrt.h" - -#include "mbusafecrt_internal.h" - -#define _CFLTCVT _safecrt_cfltcvt - -//typedef __int64_t __int64; -typedef double _CRT_DOUBLE; -typedef char _TCHAR; -typedef char TCHAR; -#define _T(x) x -/* -Buffer size required to be passed to _gcvt, fcvt and other fp conversion routines -*/ -#define _CVTBUFSIZE (309+40) /* # of digits in max. dp value + slop */ - -//------------------------------------------------------------------------------ -// This code was taken from the 'ouput.c' file located in Visual Studio 8 (i.e. 2005) -// in the '\Microsoft Visual Studio 8\VC\crt\src' directory. It was moved into -// this file to support only the '_output' function used by _vscprintf() in vsprintf.c -// UNUSED / NON-RELEVANT PORTIONS OF THE CODE HAVE BEEN REMOVED - do not try and -// use it to generate any other safecrt 'output' functions -// -// Noteable modifications -// - changed FILE to miniFILE (defined in mbusafecrt_internal.h) -// - removed _soutput_s - it was unused in this case and conflicted with output.inl -// - changed #define SHORT_IS_INT to true varargs promotes shorts to ints in GCC -// - removed definition of __lookuptable_s when using FORMAT_VALIDATIONS, we don't use them - -// 7/03/07 - Created by Stephen Shaw (steshaw) -//------------------------------------------------------------------------------ - - -/* temporary work-around for compiler without 64-bit support */ -#ifndef _INTEGRAL_MAX_BITS -#define _INTEGRAL_MAX_BITS 64 -#endif /* _INTEGRAL_MAX_BITS */ - -#include -#include -#include -#include -#include -#include -#include - -#define _MBTOWC(x,y,z) _minimal_chartowchar( x, y ) - -#undef _malloc_crt -#define _malloc_crt malloc - -#undef _free_crt -#define _free_crt free - -// SNIP -srs 7/3/07 - -#ifndef _CFLTCVT -#define _CFLTCVT _cfltcvt -#endif /* _CFLTCVT */ - -#ifndef _CLDCVT -#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 - -/* int/long/short/pointer sizes */ - -/* the following should be set depending on the sizes of various types */ -#if __LP64__ - #define LONG_IS_INT 0 - CASSERT(sizeof(long) > sizeof(int)); -#else - #define LONG_IS_INT 1 /* 1 means long is same size as int */ - CASSERT(sizeof(long) == sizeof(int)); -#endif - -#ifdef __GNUC_VA_LIST - // GCC: short is not int, but GCC promotes va_arg to int - #define SHORT_IS_INT 1 -#else - #define SHORT_IS_INT 0 /* 1 means short is same size as int */ - CASSERT(sizeof(short) != sizeof(int)); -#endif - -#define LONGLONG_IS_INT64 1 /* 1 means long long is same as int64 */ - CASSERT(sizeof(long long) == sizeof(int64_t)); - -#if defined (_WIN64) - #define PTR_IS_INT 0 /* 1 means ptr is same size as int */ - CASSERT(sizeof(void *) != sizeof(int)); - #if __LP64__ - #define PTR_IS_LONG 1 /* 1 means ptr is same size as long */ - CASSERT(sizeof(void *) == sizeof(long)); - #else - #define PTR_IS_LONG 0 /* 1 means ptr is same size as long */ - CASSERT(sizeof(void *) != sizeof(long)); - #endif - #define PTR_IS_INT64 1 /* 1 means ptr is same size as int64 */ - CASSERT(sizeof(void *) == sizeof(int64_t)); -#else /* defined (_WIN64) */ - #define PTR_IS_INT 1 /* 1 means ptr is same size as int */ - CASSERT(sizeof(void *) == sizeof(int)); - #define PTR_IS_LONG 1 /* 1 means ptr is same size as long */ - CASSERT(sizeof(void *) == sizeof(long)); - #define PTR_IS_INT64 0 /* 1 means ptr is same size as int64 */ - CASSERT(sizeof(void *) != sizeof(int64_t)); -#endif /* defined (_WIN64) */ - -#ifndef __GNUC_VA_LIST - -#if LONGLONG_IS_INT64 - #define get_long_long_arg(x) (long long)get_int64_arg(x) -#endif /* LONGLONG_IS_INT64 */ - -#if LONG_IS_INT - #define get_long_arg(x) (long)get_int_arg(x) -#endif /* LONG_IS_INT */ - -#ifndef _UNICODE -#if SHORT_IS_INT - #define get_short_arg(x) (short)get_int_arg(x) -#endif /* SHORT_IS_INT */ -#endif /* _UNICODE */ - -#if PTR_IS_INT - #define get_ptr_arg(x) (void *)(intptr_t)get_int_arg(x) -#elif PTR_IS_LONG - #define get_ptr_arg(x) (void *)(intptr_t)get_long_arg(x) -#elif PTR_IS_INT64 - #define get_ptr_arg(x) (void *)get_int64_arg(x) -#else /* PTR_IS_INT64 */ - #error Size of pointer must be same as size of int or long -#endif /* PTR_IS_INT64 */ - -#endif // __GNUC_VA_LIST - - -/* CONSTANTS */ - -/* size of conversion buffer (ANSI-specified minimum is 509) */ - -#define BUFFERSIZE 512 -#define MAXPRECISION BUFFERSIZE - -#if BUFFERSIZE < _CVTBUFSIZE + 6 -/* - * Buffer needs to be big enough for default minimum precision - * when converting floating point needs bigger buffer, and malloc - * fails - */ -#error Conversion buffer too small for max double. -#endif /* BUFFERSIZE < _CVTBUFSIZE + 6 */ - -/* flag definitions */ -#define FL_SIGN 0x00001 /* put plus or minus in front */ -#define FL_SIGNSP 0x00002 /* put space or minus in front */ -#define FL_LEFT 0x00004 /* left justify */ -#define FL_LEADZERO 0x00008 /* pad with leading zeros */ -#define FL_LONG 0x00010 /* long value given */ -#define FL_SHORT 0x00020 /* short value given */ -#define FL_SIGNED 0x00040 /* signed data given */ -#define FL_ALTERNATE 0x00080 /* alternate form requested */ -#define FL_NEGATIVE 0x00100 /* value is negative */ -#define FL_FORCEOCTAL 0x00200 /* force leading '0' for octals */ -#define FL_LONGDOUBLE 0x00400 /* long double value given */ -#define FL_WIDECHAR 0x00800 /* wide characters */ -#define FL_LONGLONG 0x01000 /* long long value given */ -#define FL_I64 0x08000 /* __int64 value given */ - -/* state definitions */ -enum STATE { - ST_NORMAL, /* normal state; outputting literal chars */ - ST_PERCENT, /* just read '%' */ - ST_FLAG, /* just read flag character */ - ST_WIDTH, /* just read width specifier */ - ST_DOT, /* just read '.' */ - ST_PRECIS, /* just read precision specifier */ - ST_SIZE, /* just read size specifier */ - ST_TYPE /* just read type specifier */ -#ifdef FORMAT_VALIDATIONS - ,ST_INVALID /* Invalid format */ -#endif /* FORMAT_VALIDATIONS */ - -}; - -#ifdef FORMAT_VALIDATIONS -#define NUMSTATES (ST_INVALID + 1) -#else /* FORMAT_VALIDATIONS */ -#define NUMSTATES (ST_TYPE + 1) -#endif /* FORMAT_VALIDATIONS */ - -/* character type values */ -enum CHARTYPE { - CH_OTHER, /* character with no special meaning */ - CH_PERCENT, /* '%' */ - CH_DOT, /* '.' */ - CH_STAR, /* '*' */ - CH_ZERO, /* '0' */ - CH_DIGIT, /* '1'..'9' */ - CH_FLAG, /* ' ', '+', '-', '#' */ - CH_SIZE, /* 'h', 'l', 'L', 'N', 'F', 'w' */ - CH_TYPE /* type specifying character */ -}; - -/* static data (read only, since we are re-entrant) */ -#if defined (_UNICODE) || defined (CPRFLAG) || defined (FORMAT_VALIDATIONS) -extern const char __nullstring[]; /* string to print on null ptr */ -extern const char16_t __wnullstring[]; /* string to print on null ptr */ -#else /* defined (_UNICODE) || defined (CPRFLAG) || defined (FORMAT_VALIDATIONS) */ -static const char __nullstring[] = "(null)"; /* string to print on null ptr */ -static const char16_t __wnullstring[] = { '(', 'n', 'u', 'l', 'l', ')', '\0' };/* string to print on null ptr */ -#endif /* defined (_UNICODE) || defined (CPRFLAG) || defined (FORMAT_VALIDATIONS) */ - -/* The state table. This table is actually two tables combined into one. */ -/* The lower nybble of each byte gives the character class of any */ -/* character; while the uper nybble of the byte gives the next state */ -/* to enter. See the macros below the table for details. */ -/* */ -/* The table is generated by maketabc.c -- use this program to make */ -/* changes. */ - -#ifndef FORMAT_VALIDATIONS -#if defined (_UNICODE) || defined (CPRFLAG) -extern const char __lookuptable[]; -#else /* defined (_UNICODE) || defined (CPRFLAG) */ -//extern const char __lookuptable[] = { -const char __lookuptable[] = { - /* ' ' */ 0x06, - /* '!' */ 0x00, - /* '"' */ 0x00, - /* '#' */ 0x06, - /* '$' */ 0x00, - /* '%' */ 0x01, - /* '&' */ 0x00, - /* ''' */ 0x00, - /* '(' */ 0x10, - /* ')' */ 0x00, - /* '*' */ 0x03, - /* '+' */ 0x06, - /* ',' */ 0x00, - /* '-' */ 0x06, - /* '.' */ 0x02, - /* '/' */ 0x10, - /* '0' */ 0x04, - /* '1' */ 0x45, - /* '2' */ 0x45, - /* '3' */ 0x45, - /* '4' */ 0x05, - /* '5' */ 0x05, - /* '6' */ 0x05, - /* '7' */ 0x05, - /* '8' */ 0x05, - /* '9' */ 0x35, - /* ':' */ 0x30, - /* ';' */ 0x00, - /* '<' */ 0x50, - /* '=' */ 0x00, - /* '>' */ 0x00, - /* '?' */ 0x00, - /* '@' */ 0x00, - /* 'A' */ 0x20, // Disable %A format - /* 'B' */ 0x20, - /* 'C' */ 0x38, - /* 'D' */ 0x50, - /* 'E' */ 0x58, - /* 'F' */ 0x07, - /* 'G' */ 0x08, - /* 'H' */ 0x00, - /* 'I' */ 0x37, - /* 'J' */ 0x30, - /* 'K' */ 0x30, - /* 'L' */ 0x57, - /* 'M' */ 0x50, - /* 'N' */ 0x07, - /* 'O' */ 0x00, - /* 'P' */ 0x00, - /* 'Q' */ 0x20, - /* 'R' */ 0x20, - /* 'S' */ 0x08, - /* 'T' */ 0x00, - /* 'U' */ 0x00, - /* 'V' */ 0x00, - /* 'W' */ 0x00, - /* 'X' */ 0x08, - /* 'Y' */ 0x60, - /* 'Z' */ 0x68, - /* '[' */ 0x60, - /* '\' */ 0x60, - /* ']' */ 0x60, - /* '^' */ 0x60, - /* '_' */ 0x00, - /* '`' */ 0x00, - /* 'a' */ 0x70, // Disable %a format - /* 'b' */ 0x70, - /* 'c' */ 0x78, - /* 'd' */ 0x78, - /* 'e' */ 0x78, - /* 'f' */ 0x78, - /* 'g' */ 0x08, - /* 'h' */ 0x07, - /* 'i' */ 0x08, - /* 'j' */ 0x00, - /* 'k' */ 0x00, - /* 'l' */ 0x07, - /* 'm' */ 0x00, - /* 'n' */ 0x00, // Disable %n format - /* 'o' */ 0x08, - /* 'p' */ 0x08, - /* 'q' */ 0x00, - /* 'r' */ 0x00, - /* 's' */ 0x08, - /* 't' */ 0x00, - /* 'u' */ 0x08, - /* 'v' */ 0x00, - /* 'w' */ 0x07, - /* 'x' */ 0x08 -}; - -#endif /* defined (_UNICODE) || defined (CPRFLAG) */ - -#else /* FORMAT_VALIDATIONS */ -// SNIP -srs 7/3/07 -#error code has been removed -#endif /* FORMAT_VALIDATIONS */ - -#define FIND_CHAR_CLASS(lookuptbl, c) \ - ((c) < _T(' ') || (c) > _T('x') ? \ - CH_OTHER \ - : \ - (enum CHARTYPE)(lookuptbl[(c)-_T(' ')] & 0xF)) - -#define FIND_NEXT_STATE(lookuptbl, class, state) \ - (enum STATE)(lookuptbl[(class) * NUMSTATES + (state)] >> 4) - -/* - * Note: CPRFLAG and _UNICODE cases are currently mutually exclusive. - */ - -/* prototypes */ - -#ifdef CPRFLAG - -#define WRITE_CHAR(ch, pnw) write_char(ch, pnw) -#define WRITE_MULTI_CHAR(ch, num, pnw) write_multi_char(ch, num, pnw) -#define WRITE_STRING(s, len, pnw) write_string(s, len, pnw) -#define WRITE_WSTRING(s, len, pnw) write_wstring(s, len, pnw) - -LOCAL(void) write_char(_TCHAR ch, int *pnumwritten); -LOCAL(void) write_multi_char(_TCHAR ch, int num, int *pnumwritten); -LOCAL(void) write_string(const _TCHAR *string, int len, int *numwritten); -LOCAL(void) write_wstring(const char16_t *string, int len, int *numwritten); - -#else /* CPRFLAG */ - -#define WRITE_CHAR(ch, pnw) write_char(ch, stream, pnw) -#define WRITE_MULTI_CHAR(ch, num, pnw) write_multi_char(ch, num, stream, pnw) -#define WRITE_STRING(s, len, pnw) write_string(s, len, stream, pnw) -#define WRITE_WSTRING(s, len, pnw) write_wstring(s, len, stream, pnw) - -LOCAL(void) write_char(_TCHAR ch, miniFILE *f, int *pnumwritten); -LOCAL(void) write_multi_char(_TCHAR ch, int num, miniFILE *f, int *pnumwritten); -LOCAL(void) write_string(const _TCHAR *string, int len, miniFILE *f, int *numwritten); -//LOCAL(void) write_wstring(const char16_t *string, int len, miniFILE *f, int *numwritten); - -#endif /* CPRFLAG */ - -#ifdef __GNUC_VA_LIST - - #define get_short_arg(list) va_arg(*list, int) // GCC promotes va_arg shorts into int values - #define get_int_arg(list) va_arg(*list, int) - #define get_long_arg(list) va_arg(*list, long) - #define get_long_long_arg(list) va_arg(*list, long long) - #define get_int64_arg(list) va_arg(*list, __int64) - #define get_crtdouble_arg(list) va_arg(*list, _CRT_DOUBLE) - #define get_ptr_arg(list) va_arg(*list, void *) - -#else // __GNUC_VA_LIST - -__inline int __cdecl get_int_arg(va_list *pargptr); - -#ifndef _UNICODE -#if !SHORT_IS_INT -__inline short __cdecl get_short_arg(va_list *pargptr); -#endif /* !SHORT_IS_INT */ -#endif /* _UNICODE */ - -#if !LONG_IS_INT -__inline long __cdecl get_long_arg(va_list *pargptr); -#endif /* !LONG_IS_INT */ - -#if !LONGLONG_IS_INT64 -__inline long long __cdecl get_long_long_arg(va_list *pargptr); -#endif /* !LONGLONG_IS_INT64 */ - -#if _INTEGRAL_MAX_BITS >= 64 -__inline __int64 __cdecl get_int64_arg(va_list *pargptr); -#endif /* _INTEGRAL_MAX_BITS >= 64 */ - -#endif // __GNUC_VA_LIST - -#ifdef CPRFLAG -LOCAL(int) output(const _TCHAR *, _locale_t , va_list); -_CRTIMP int __cdecl _vtcprintf_l (const _TCHAR *, _locale_t, va_list); -_CRTIMP int __cdecl _vtcprintf_s_l (const _TCHAR *, _locale_t, va_list); -_CRTIMP int __cdecl _vtcprintf_p_l (const _TCHAR *, _locale_t, va_list); - - -/*** -*int _cprintf(format, arglist) - write formatted output directly to console -* -*Purpose: -* Writes formatted data like printf, but uses console I/O functions. -* -*Entry: -* char *format - format string to determine data formats -* arglist - list of POINTERS to where to put data -* -*Exit: -* returns number of characters written -* -*Exceptions: -* -*******************************************************************************/ -#ifndef FORMAT_VALIDATIONS -_CRTIMP int __cdecl _tcprintf_l ( - const _TCHAR * format, - _locale_t plocinfo, - ... - ) -#else /* FORMAT_VALIDATIONS */ -_CRTIMP int __cdecl _tcprintf_s_l ( - const _TCHAR * format, - _locale_t plocinfo, - ... - ) -#endif /* FORMAT_VALIDATIONS */ - -{ - int ret; - va_list arglist; - va_start(arglist, plocinfo); - -#ifndef FORMAT_VALIDATIONS - ret = _vtcprintf_l(format, plocinfo, arglist); -#else /* FORMAT_VALIDATIONS */ - ret = _vtcprintf_s_l(format, plocinfo, arglist); - -#endif /* FORMAT_VALIDATIONS */ - - va_end(arglist); - - return ret; -} - -#ifndef FORMAT_VALIDATIONS -_CRTIMP int __cdecl _tcprintf ( - const _TCHAR * format, - ... - ) -#else /* FORMAT_VALIDATIONS */ -_CRTIMP int __cdecl _tcprintf_s ( - const _TCHAR * format, - ... - ) -#endif /* FORMAT_VALIDATIONS */ - -{ - int ret; - va_list arglist; - - va_start(arglist, format); - -#ifndef FORMAT_VALIDATIONS - ret = _vtcprintf_l(format, NULL, arglist); -#else /* FORMAT_VALIDATIONS */ - ret = _vtcprintf_s_l(format, NULL, arglist); - -#endif /* FORMAT_VALIDATIONS */ - - va_end(arglist); - - return ret; -} - -#endif /* CPRFLAG */ - - -/*** -*int _output(stream, format, argptr), static int output(format, argptr) -* -*Purpose: -* Output performs printf style output onto a stream. It is called by -* printf/fprintf/sprintf/vprintf/vfprintf/vsprintf to so the dirty -* work. In multi-thread situations, _output assumes that the given -* stream is already locked. -* -* Algorithm: -* The format string is parsed by using a finite state automaton -* based on the current state and the current character read from -* the format string. Thus, looping is on a per-character basis, -* not a per conversion specifier basis. Once the format specififying -* character is read, output is performed. -* -*Entry: -* FILE *stream - stream for output -* char *format - printf style format string -* va_list argptr - pointer to list of subsidiary arguments -* -*Exit: -* Returns the number of characters written, or -1 if an output error -* occurs. -*ifdef _UNICODE -* The wide-character flavour returns the number of wide-characters written. -*endif -* -*Exceptions: -* -*******************************************************************************/ -#ifdef CPRFLAG -#ifndef FORMAT_VALIDATIONS -_CRTIMP int __cdecl _vtcprintf ( - const _TCHAR *format, - va_list argptr - ) -{ - return _vtcprintf_l(format, NULL, argptr); -} - -#else /* FORMAT_VALIDATIONS */ -_CRTIMP int __cdecl _vtcprintf_s ( - const _TCHAR *format, - va_list argptr - ) -{ - return _vtcprintf_s_l(format, NULL, argptr); -} - -#endif /* FORMAT_VALIDATIONS */ -#endif /* CPRFLAG */ - -#ifdef CPRFLAG -#ifndef FORMAT_VALIDATIONS -_CRTIMP int __cdecl _vtcprintf_l ( -#else /* FORMAT_VALIDATIONS */ -_CRTIMP int __cdecl _vtcprintf_s_l ( -#endif /* FORMAT_VALIDATIONS */ -#else /* CPRFLAG */ - -#ifdef _UNICODE -#ifndef FORMAT_VALIDATIONS -int __cdecl _woutput ( - miniFILE *stream, -#else /* FORMAT_VALIDATIONS */ -int __cdecl _woutput_s ( - miniFILE *stream, -#endif /* FORMAT_VALIDATIONS */ -#else /* _UNICODE */ -#ifndef FORMAT_VALIDATIONS -int __cdecl _output ( - miniFILE *stream, -#else /* FORMAT_VALIDATIONS */ - int __cdecl _output_s ( - miniFILE *stream, - -#endif /* FORMAT_VALIDATIONS */ -#endif /* _UNICODE */ - -#endif /* CPRFLAG */ - const _TCHAR *format, - va_list argptr - ) -{ - int hexadd=0; /* offset to add to number to get 'a'..'f' */ - TCHAR ch; /* character just read */ - int flags=0; /* flag word -- see #defines above for flag values */ - enum STATE state; /* current state */ - enum CHARTYPE chclass; /* class of current character */ - int radix; /* current conversion radix */ - int charsout; /* characters currently written so far, -1 = IO error */ - int fldwidth = 0; /* selected field width -- 0 means default */ - int precision = 0; /* selected precision -- -1 means default */ - TCHAR prefix[2]; /* numeric prefix -- up to two characters */ - int prefixlen=0; /* length of prefix -- 0 means no prefix */ - int capexp = 0; /* non-zero = 'E' exponent signifient, zero = 'e' */ - int no_output=0; /* non-zero = prodcue no output for this specifier */ - union { - const char *sz; /* pointer text to be printed, not zero terminated */ - const char16_t *wz; - } text; - - int textlen; /* length of the text in bytes/wchars to be printed. - textlen is in multibyte or wide chars if _UNICODE */ - union { - char sz[BUFFERSIZE]; -#ifdef _UNICODE - char16_t wz[BUFFERSIZE]; -#endif /* _UNICODE */ - } buffer; - char16_t wchar; /* temp char16_t */ - int buffersize; /* size of text.sz (used only for the call to _cfltcvt) */ - int bufferiswide=0; /* non-zero = buffer contains wide chars already */ - -#ifndef CPRFLAG - _VALIDATE_RETURN( (stream != NULL), EINVAL, -1); -#endif /* CPRFLAG */ - _VALIDATE_RETURN( (format != NULL), EINVAL, -1); - - charsout = 0; /* no characters written yet */ - textlen = 0; /* no text yet */ - state = ST_NORMAL; /* starting state */ - buffersize = 0; - - /* main loop -- loop while format character exist and no I/O errors */ - while ((ch = *format++) != _T('\0') && charsout >= 0) { -#ifndef FORMAT_VALIDATIONS - chclass = FIND_CHAR_CLASS(__lookuptable, ch); /* find character class */ - state = FIND_NEXT_STATE(__lookuptable, chclass, state); /* find next state */ -#else /* FORMAT_VALIDATIONS */ - chclass = FIND_CHAR_CLASS(__lookuptable_s, ch); /* find character class */ - state = FIND_NEXT_STATE(__lookuptable_s, chclass, state); /* find next state */ - - _VALIDATE_RETURN((state != ST_INVALID), EINVAL, -1); - -#endif /* FORMAT_VALIDATIONS */ - - /* execute code for each state */ - switch (state) { - - case ST_NORMAL: - - NORMAL_STATE: - - /* normal state -- just write character */ -#ifdef _UNICODE - bufferiswide = 1; -#else /* _UNICODE */ - bufferiswide = 0; -#endif /* _UNICODE */ - WRITE_CHAR(ch, &charsout); - break; - - case ST_PERCENT: - /* set default value of conversion parameters */ - prefixlen = fldwidth = no_output = capexp = 0; - flags = 0; - precision = -1; - bufferiswide = 0; /* default */ - break; - - case ST_FLAG: - /* set flag based on which flag character */ - switch (ch) { - case _T('-'): - flags |= FL_LEFT; /* '-' => left justify */ - break; - case _T('+'): - flags |= FL_SIGN; /* '+' => force sign indicator */ - break; - case _T(' '): - flags |= FL_SIGNSP; /* ' ' => force sign or space */ - break; - case _T('#'): - flags |= FL_ALTERNATE; /* '#' => alternate form */ - break; - case _T('0'): - flags |= FL_LEADZERO; /* '0' => pad with leading zeros */ - break; - } - break; - - case ST_WIDTH: - /* update width value */ - if (ch == _T('*')) { - /* get width from arg list */ - fldwidth = get_int_arg(&argptr); - if (fldwidth < 0) { - /* ANSI says neg fld width means '-' flag and pos width */ - flags |= FL_LEFT; - fldwidth = -fldwidth; - } - } - else { - /* add digit to current field width */ - fldwidth = fldwidth * 10 + (ch - _T('0')); - } - break; - - case ST_DOT: - /* zero the precision, since dot with no number means 0 - not default, according to ANSI */ - precision = 0; - break; - - case ST_PRECIS: - /* update precison value */ - if (ch == _T('*')) { - /* get precision from arg list */ - precision = get_int_arg(&argptr); - if (precision < 0) - precision = -1; /* neg precision means default */ - } - else { - /* add digit to current precision */ - precision = precision * 10 + (ch - _T('0')); - } - break; - - case ST_SIZE: - /* just read a size specifier, set the flags based on it */ - switch (ch) { - case _T('l'): - /* - * In order to handle the ll case, we depart from the - * simple deterministic state machine. - */ - if (*format == _T('l')) - { - ++format; - flags |= FL_LONGLONG; /* 'll' => long long */ - } - else - { - flags |= FL_LONG; /* 'l' => long int or char16_t */ - } - break; - - case _T('I'): - /* - * In order to handle the I, I32, and I64 size modifiers, we - * depart from the simple deterministic state machine. The - * code below scans for characters following the 'I', - * and defaults to 64 bit on WIN64 and 32 bit on WIN32 - */ -#if PTR_IS_INT64 - flags |= FL_I64; /* 'I' => __int64 on WIN64 systems */ -#endif /* PTR_IS_INT64 */ - if ( (*format == _T('6')) && (*(format + 1) == _T('4')) ) - { - format += 2; - flags |= FL_I64; /* I64 => __int64 */ - } - else if ( (*format == _T('3')) && (*(format + 1) == _T('2')) ) - { - format += 2; - flags &= ~FL_I64; /* I32 => __int32 */ - } - else if ( (*format == _T('d')) || - (*format == _T('i')) || - (*format == _T('o')) || - (*format == _T('u')) || - (*format == _T('x')) || - (*format == _T('X')) ) - { - /* - * Nothing further needed. %Id (et al) is - * handled just like %d, except that it defaults to 64 bits - * on WIN64. Fall through to the next iteration. - */ - } - else { - state = ST_NORMAL; - goto NORMAL_STATE; - } - break; - - case _T('h'): - flags |= FL_SHORT; /* 'h' => short int or char */ - break; - - case _T('w'): - flags |= FL_WIDECHAR; /* 'w' => wide character */ - break; - - } - break; - - case ST_TYPE: - /* we have finally read the actual type character, so we */ - /* now format and "print" the output. We use a big switch */ - /* statement that sets 'text' to point to the text that should */ - /* be printed, and 'textlen' to the length of this text. */ - /* Common code later on takes care of justifying it and */ - /* other miscellaneous chores. Note that cases share code, */ - /* in particular, all integer formatting is done in one place. */ - /* Look at those funky goto statements! */ - - switch (ch) { - - case _T('C'): /* ISO wide character */ - if (!(flags & (FL_SHORT|FL_LONG|FL_WIDECHAR))) -#ifdef _UNICODE - flags |= FL_SHORT; -#else /* _UNICODE */ - flags |= FL_WIDECHAR; /* ISO std. */ -#endif /* _UNICODE */ - /* fall into 'c' case */ - - case _T('c'): { - /* print a single character specified by int argument */ -#ifdef _UNICODE - bufferiswide = 1; - wchar = (char16_t) get_int_arg(&argptr); - if (flags & FL_SHORT) { - /* format multibyte character */ - /* this is an extension of ANSI */ - char tempchar[2]; - { - tempchar[0] = (char)(wchar & 0x00ff); - tempchar[1] = '\0'; - } - - if (_MBTOWC(buffer.wz,tempchar, MB_CUR_MAX) < 0) - { - /* ignore if conversion was unsuccessful */ - no_output = 1; - } - } else { - buffer.wz[0] = wchar; - } - text.wz = buffer.wz; - textlen = 1; /* print just a single character */ -#else /* _UNICODE */ - if (flags & (FL_LONG|FL_WIDECHAR)) { - wchar = (char16_t) get_short_arg(&argptr); - no_output = 1; - } else { - /* format multibyte character */ - /* this is an extension of ANSI */ - unsigned short temp; - wchar = (char16_t)get_int_arg(&argptr); - temp = (unsigned short)wchar; - { - buffer.sz[0] = (char) temp; - textlen = 1; - } - } - text.sz = buffer.sz; -#endif /* _UNICODE */ - } - break; - - case _T('Z'): { - /* print a Counted String */ - struct _count_string { - short Length; - short MaximumLength; - char *Buffer; - } *pstr; - - pstr = (struct _count_string *)get_ptr_arg(&argptr); - if (pstr == NULL || pstr->Buffer == NULL) { - /* null ptr passed, use special string */ - text.sz = __nullstring; - textlen = (int)strlen(text.sz); - } else { - if (flags & FL_WIDECHAR) { - text.wz = (char16_t *)pstr->Buffer; - textlen = pstr->Length / (int)sizeof(char16_t); - bufferiswide = 1; - } else { - bufferiswide = 0; - text.sz = pstr->Buffer; - textlen = pstr->Length; - } - } - } - break; - - case _T('S'): /* ISO wide character string */ -#ifndef _UNICODE - if (!(flags & (FL_SHORT|FL_LONG|FL_WIDECHAR))) - flags |= FL_WIDECHAR; -#else /* _UNICODE */ - if (!(flags & (FL_SHORT|FL_LONG|FL_WIDECHAR))) - flags |= FL_SHORT; -#endif /* _UNICODE */ - - case _T('s'): { - /* print a string -- */ - /* ANSI rules on how much of string to print: */ - /* all if precision is default, */ - /* min(precision, length) if precision given. */ - /* prints '(null)' if a null string is passed */ - - int i; - const char *p; /* temps */ - const char16_t *pwch; - - /* At this point it is tempting to use strlen(), but */ - /* if a precision is specified, we're not allowed to */ - /* scan past there, because there might be no null */ - /* at all. Thus, we must do our own scan. */ - - i = (precision == -1) ? INT_MAX : precision; - text.sz = (char *)get_ptr_arg(&argptr); - - /* scan for null upto i characters */ -#ifdef _UNICODE - if (flags & FL_SHORT) { - if (text.sz == NULL) /* NULL passed, use special string */ - text.sz = __nullstring; - p = text.sz; - for (textlen=0; textlen MAXPRECISION) - precision = MAXPRECISION; - - if (precision > BUFFERSIZE - _CVTBUFSIZE) { - precision = BUFFERSIZE - _CVTBUFSIZE; - } - - /* for safecrt, we pass along the FL_ALTERNATE flag to _safecrt_cfltcvt */ - if (flags & FL_ALTERNATE) - { - capexp |= FL_ALTERNATE; - } - - _CRT_DOUBLE tmp; - tmp=va_arg(argptr, _CRT_DOUBLE); - /* Note: assumes ch is in ASCII range */ - /* In safecrt, we provide a special version of _cfltcvt which internally calls printf (see safecrt_output_s.c) */ - _CFLTCVT(&tmp, buffer.sz, buffersize, (char)ch, precision, capexp); - - /* check if result was negative, save '-' for later */ - /* and point to positive part (this is for '0' padding) */ - if (*text.sz == '-') { - flags |= FL_NEGATIVE; - ++text.sz; - } - - textlen = (int)strlen(text.sz); /* compute length of text */ - } - break; - - case _T('d'): - case _T('i'): - /* signed decimal output */ - flags |= FL_SIGNED; - radix = 10; - goto COMMON_INT; - - case _T('u'): - radix = 10; - goto COMMON_INT; - - case _T('p'): - /* write a pointer -- this is like an integer or long */ - /* except we force precision to pad with zeros and */ - /* output in big hex. */ - - precision = 2 * sizeof(void *); /* number of hex digits needed */ -#if PTR_IS_INT64 - flags |= FL_I64; /* assume we're converting an int64 */ -#elif !PTR_IS_INT - flags |= FL_LONG; /* assume we're converting a long */ -#endif /* !PTR_IS_INT */ - /* DROP THROUGH to hex formatting */ - - case _T('X'): - /* unsigned upper hex output */ - hexadd = _T('A') - _T('9') - 1; /* set hexadd for uppercase hex */ - goto COMMON_HEX; - - case _T('x'): - /* unsigned lower hex output */ - hexadd = _T('a') - _T('9') - 1; /* set hexadd for lowercase hex */ - /* DROP THROUGH TO COMMON_HEX */ - - COMMON_HEX: - radix = 16; - if (flags & FL_ALTERNATE) { - /* alternate form means '0x' prefix */ - prefix[0] = _T('0'); - prefix[1] = (TCHAR)(_T('x') - _T('a') + _T('9') + 1 + hexadd); /* 'x' or 'X' */ - prefixlen = 2; - } - goto COMMON_INT; - - case _T('o'): - /* unsigned octal output */ - radix = 8; - if (flags & FL_ALTERNATE) { - /* alternate form means force a leading 0 */ - flags |= FL_FORCEOCTAL; - } - /* DROP THROUGH to COMMON_INT */ - - COMMON_INT: { - /* This is the general integer formatting routine. */ - /* Basically, we get an argument, make it positive */ - /* if necessary, and convert it according to the */ - /* correct radix, setting text and textlen */ - /* appropriately. */ - -#if _INTEGRAL_MAX_BITS >= 64 -// unsigned __int64 number; /* number to convert */ - __uint64_t number; /* number to convert */ - int digit; /* ascii value of digit */ - __int64 l; /* temp long value */ -#else /* _INTEGRAL_MAX_BITS >= 64 */ - unsigned long number; /* number to convert */ - int digit; /* ascii value of digit */ - long l; /* temp long value */ -#endif /* _INTEGRAL_MAX_BITS >= 64 */ - - /* 1. read argument into l, sign extend as needed */ -#if _INTEGRAL_MAX_BITS >= 64 - if (flags & FL_I64) - l = get_int64_arg(&argptr); - else -#endif /* _INTEGRAL_MAX_BITS >= 64 */ - - if (flags & FL_LONGLONG) - l = get_long_long_arg(&argptr); - else - -#if !LONG_IS_INT - if (flags & FL_LONG) - l = get_long_arg(&argptr); - else -#endif /* !LONG_IS_INT */ - -#if !SHORT_IS_INT - if (flags & FL_SHORT) { - if (flags & FL_SIGNED) - l = (short) get_int_arg(&argptr); /* sign extend */ - else - l = (unsigned short) get_int_arg(&argptr); /* zero-extend*/ - - } else -#endif /* !SHORT_IS_INT */ - { - if (flags & FL_SIGNED) - l = get_int_arg(&argptr); /* sign extend */ - else - l = (unsigned int) get_int_arg(&argptr); /* zero-extend*/ - - } - - /* 2. check for negative; copy into number */ - if ( (flags & FL_SIGNED) && l < 0) { - number = -l; - flags |= FL_NEGATIVE; /* remember negative sign */ - } else { - number = l; - } - -#if _INTEGRAL_MAX_BITS >= 64 - if ( (flags & FL_I64) == 0 && (flags & FL_LONGLONG) == 0 ) { - /* - * Unless printing a full 64-bit value, insure values - * here are not in cananical longword format to prevent - * the sign extended upper 32-bits from being printed. - */ - number &= 0xffffffff; - } -#endif /* _INTEGRAL_MAX_BITS >= 64 */ - - /* 3. check precision value for default; non-default */ - /* turns off 0 flag, according to ANSI. */ - if (precision < 0) - precision = 1; /* default precision */ - else { - flags &= ~FL_LEADZERO; - if (precision > MAXPRECISION) - precision = MAXPRECISION; - } - - /* 4. Check if data is 0; if so, turn off hex prefix */ - if (number == 0) - prefixlen = 0; - - /* 5. Convert data to ASCII -- note if precision is zero */ - /* and number is zero, we get no digits at all. */ - - char *sz; - sz = &buffer.sz[BUFFERSIZE-1]; /* last digit at end of buffer */ - - while (precision-- > 0 || number != 0) { - digit = (int)(number % radix) + '0'; - number /= radix; /* reduce number */ - if (digit > '9') { - /* a hex digit, make it a letter */ - digit += hexadd; - } - *sz-- = (char)digit; /* store the digit */ - } - - textlen = (int)((char *)&buffer.sz[BUFFERSIZE-1] - sz); /* compute length of number */ - ++sz; /* text points to first digit now */ - - - /* 6. Force a leading zero if FORCEOCTAL flag set */ - if ((flags & FL_FORCEOCTAL) && (textlen == 0 || sz[0] != '0')) { - *--sz = '0'; - ++textlen; /* add a zero */ - } - - text.sz = sz; - } - break; - } - - - /* At this point, we have done the specific conversion, and */ - /* 'text' points to text to print; 'textlen' is length. Now we */ - /* justify it, put on prefixes, leading zeros, and then */ - /* print it. */ - - if (!no_output) { - int padding; /* amount of padding, negative means zero */ - - if (flags & FL_SIGNED) { - if (flags & FL_NEGATIVE) { - /* prefix is a '-' */ - prefix[0] = _T('-'); - prefixlen = 1; - } - else if (flags & FL_SIGN) { - /* prefix is '+' */ - prefix[0] = _T('+'); - prefixlen = 1; - } - else if (flags & FL_SIGNSP) { - /* prefix is ' ' */ - prefix[0] = _T(' '); - prefixlen = 1; - } - } - - /* calculate amount of padding -- might be negative, */ - /* but this will just mean zero */ - padding = fldwidth - textlen - prefixlen; - - /* put out the padding, prefix, and text, in the correct order */ - - if (!(flags & (FL_LEFT | FL_LEADZERO))) { - /* pad on left with blanks */ - WRITE_MULTI_CHAR(_T(' '), padding, &charsout); - } - - /* write prefix */ - WRITE_STRING(prefix, prefixlen, &charsout); - - if ((flags & FL_LEADZERO) && !(flags & FL_LEFT)) { - /* write leading zeros */ - WRITE_MULTI_CHAR(_T('0'), padding, &charsout); - } - - /* write text */ -#ifndef _UNICODE - if (bufferiswide && (textlen > 0)) { - charsout = -1; - } else { - WRITE_STRING(text.sz, textlen, &charsout); - } -#else /* _UNICODE */ - if (!bufferiswide && textlen > 0) { - char *p; - int retval = 0 - int count; - - p = text.sz; - count = textlen; - while (count-- > 0) { - retval = _MBTOWC(&wchar, p, MB_CUR_MAX); - if (retval <= 0) { - charsout = -1; - break; - } - WRITE_CHAR(wchar, &charsout); - p += retval; - } - } else { - WRITE_STRING(text.wz, textlen, &charsout); - } -#endif /* _UNICODE */ - - if (charsout >= 0 && (flags & FL_LEFT)) { - /* pad on right with blanks */ - WRITE_MULTI_CHAR(_T(' '), padding, &charsout); - } - - /* we're done! */ - } - break; - } - } - -#ifdef FORMAT_VALIDATIONS - /* The format string shouldn't be incomplete - i.e. when we are finished - with the format string, the last thing we should have encountered - should have been a regular char to be output or a type specifier. Else - the format string was incomplete */ - _VALIDATE_RETURN(((state == ST_NORMAL) || (state == ST_TYPE)), EINVAL, -1); -#endif /* FORMAT_VALIDATIONS */ - - return charsout; /* return value = number of characters written */ -} - -/* - * Future Optimizations for swprintf: - * - Don't free the memory used for converting the buffer to wide chars. - * Use realloc if the memory is not sufficient. Free it at the end. - */ - -/*** -*void write_char(char ch, int *pnumwritten) -*ifdef _UNICODE -*void write_char(char16_t ch, FILE *f, int *pnumwritten) -*endif -*void write_char(char ch, FILE *f, int *pnumwritten) -* -*Purpose: -* Writes a single character to the given file/console. If no error occurs, -* then *pnumwritten is incremented; otherwise, *pnumwritten is set -* to -1. -* -*Entry: -* _TCHAR ch - character to write -* FILE *f - file to write to -* int *pnumwritten - pointer to integer to update with total chars written -* -*Exit: -* No return value. -* -*Exceptions: -* -*******************************************************************************/ - -#ifdef CPRFLAG - -LOCAL(void) write_char ( - _TCHAR ch, - int *pnumwritten - ) -{ -#ifdef _UNICODE - if (_putwch_nolock(ch) == WEOF) -#else /* _UNICODE */ - if (_putch_nolock(ch) == EOF) -#endif /* _UNICODE */ - *pnumwritten = -1; - else - ++(*pnumwritten); -} - -#else /* CPRFLAG */ - -LOCAL(void) write_char ( - _TCHAR ch, - miniFILE *f, - int *pnumwritten - ) -{ - if ( (f->_flag & _IOSTRG) && f->_base == NULL) - { - ++(*pnumwritten); - return; - } -#ifdef _UNICODE - if (_putwc_nolock(ch, f) == WEOF) -#else /* _UNICODE */ - if (_putc_nolock(ch, f) == EOF) -#endif /* _UNICODE */ - *pnumwritten = -1; - else - ++(*pnumwritten); -} - -#endif /* CPRFLAG */ - -/*** -*void write_multi_char(char ch, int num, int *pnumwritten) -*ifdef _UNICODE -*void write_multi_char(char16_t ch, int num, FILE *f, int *pnumwritten) -*endif -*void write_multi_char(char ch, int num, FILE *f, int *pnumwritten) -* -*Purpose: -* Writes num copies of a character to the given file/console. If no error occurs, -* then *pnumwritten is incremented by num; otherwise, *pnumwritten is set -* to -1. If num is negative, it is treated as zero. -* -*Entry: -* _TCHAR ch - character to write -* int num - number of times to write the characters -* FILE *f - file to write to -* int *pnumwritten - pointer to integer to update with total chars written -* -*Exit: -* No return value. -* -*Exceptions: -* -*******************************************************************************/ - -#ifdef CPRFLAG -LOCAL(void) write_multi_char ( - _TCHAR ch, - int num, - int *pnumwritten - ) -{ - while (num-- > 0) { - write_char(ch, pnumwritten); - if (*pnumwritten == -1) - break; - } -} - -#else /* CPRFLAG */ - -LOCAL(void) write_multi_char ( - _TCHAR ch, - int num, - miniFILE *f, - int *pnumwritten - ) -{ - while (num-- > 0) { - write_char(ch, f, pnumwritten); - if (*pnumwritten == -1) - break; - } -} - -#endif /* CPRFLAG */ - -/*** -*void write_string(const char *string, int len, int *pnumwritten) -*void write_string(const char *string, int len, FILE *f, int *pnumwritten) -*ifdef _UNICODE -*void write_string(const char16_t *string, int len, FILE *f, int *pnumwritten) -*endif -*void write_wstring(const char16_t *string, int len, int *pnumwritten) -*void write_wstring(const char16_t *string, int len, FILE *f, int *pnumwritten) -* -*Purpose: -* Writes a string of the given length to the given file. If no error occurs, -* then *pnumwritten is incremented by len; otherwise, *pnumwritten is set -* to -1. If len is negative, it is treated as zero. -* -*Entry: -* _TCHAR *string - string to write (NOT null-terminated) -* int len - length of string -* FILE *f - file to write to -* int *pnumwritten - pointer to integer to update with total chars written -* -*Exit: -* No return value. -* -*Exceptions: -* -*******************************************************************************/ - -#ifdef CPRFLAG - -LOCAL(void) write_string ( - const _TCHAR *string, - int len, - int *pnumwritten - ) -{ - while (len-- > 0) { - write_char(*string++, pnumwritten); - if (*pnumwritten == -1) - { - if (errno == EILSEQ) - write_char(_T('?'), pnumwritten); - else - break; - } - } -} - -#else /* CPRFLAG */ - -LOCAL(void) write_string ( - const _TCHAR *string, - int len, - miniFILE *f, - int *pnumwritten - ) -{ - if ( (f->_flag & _IOSTRG) && f->_base == NULL) - { - (*pnumwritten) += len; - return; - } - while (len-- > 0) { - write_char(*string++, f, pnumwritten); - if (*pnumwritten == -1) - { - if (errno == EILSEQ) - write_char(_T('?'), f, pnumwritten); - else - break; - } - } -} -#endif /* CPRFLAG */ - - -// For GCC 64 bit, we can't cast to va_list *, so we need to make these functions defines. -#ifndef __GNUC_VA_LIST - -/*** -*int get_int_arg(va_list *pargptr) -* -*Purpose: -* Gets an int argument off the given argument list and updates *pargptr. -* -*Entry: -* va_list *pargptr - pointer to argument list; updated by function -* -*Exit: -* Returns the integer argument read from the argument list. -* -*Exceptions: -* -*******************************************************************************/ - -__inline int __cdecl get_int_arg ( - va_list *pargptr - ) -{ - return va_arg(*pargptr, int); -} - -/*** -*long get_long_arg(va_list *pargptr) -* -*Purpose: -* Gets an long argument off the given argument list and updates *pargptr. -* -*Entry: -* va_list *pargptr - pointer to argument list; updated by function -* -*Exit: -* Returns the long argument read from the argument list. -* -*Exceptions: -* -*******************************************************************************/ - -#if !LONG_IS_INT -__inline long __cdecl get_long_arg ( - va_list *pargptr - ) -{ - return va_arg(*pargptr, long); -} -#endif /* !LONG_IS_INT */ - -#if !LONGLONG_IS_INT64 -__inline long long __cdecl get_long_long_arg ( - va_list *pargptr - ) -{ - return va_arg(*pargptr, long long); -} -#endif /* !LONGLONG_IS_INT64 */ - -#if _INTEGRAL_MAX_BITS >= 64 -__inline __int64 __cdecl get_int64_arg ( - va_list *pargptr - ) -{ - return va_arg(*pargptr, __int64); -} -#endif /* _INTEGRAL_MAX_BITS >= 64 */ - -#ifndef _UNICODE -/*** -*short get_short_arg(va_list *pargptr) -* -*Purpose: -* Gets a short argument off the given argument list and updates *pargptr. -* *** CURRENTLY ONLY USED TO GET A char16_t, IFDEF _INTL *** -* -*Entry: -* va_list *pargptr - pointer to argument list; updated by function -* -*Exit: -* Returns the short argument read from the argument list. -* -*Exceptions: -* -*******************************************************************************/ - -#if !SHORT_IS_INT -__inline short __cdecl get_short_arg ( - va_list *pargptr - ) -{ - return va_arg(*pargptr, short); -} -#endif /* !SHORT_IS_INT */ - -#endif /* _UNICODE */ - -#endif // __GNUC_VA_LIST - diff --git a/pal/src/safecrt/snprintf.c b/pal/src/safecrt/snprintf.c deleted file mode 100644 index 7853320b42d..00000000000 --- a/pal/src/safecrt/snprintf.c +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*** -*snprintf.c - "Count" version of sprintf -* - -* -*Purpose: -* The _snprintf() flavor takes a count argument that is -* the max number of bytes that should be written to the -* user's buffer. -* -*******************************************************************************/ - -#define _COUNT_ 1 -#include "sprintf.c" diff --git a/pal/src/safecrt/splitpath_s.c b/pal/src/safecrt/splitpath_s.c deleted file mode 100644 index a7fc9306108..00000000000 --- a/pal/src/safecrt/splitpath_s.c +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*** -*splitpath_s.c - break down path name into components -* - -* -*Purpose: -* To provide support for accessing the individual components of an -* arbitrary path name -* -*******************************************************************************/ - -#include -#include -#include -#include "internal_securecrt.h" - -#include "mbusafecrt_internal.h" - -#define _FUNC_PROLOGUE -#define _FUNC_NAME _splitpath_s -#define _CHAR char -#define _TCSNCPY_S strncpy_s -#define _T(_Character) _Character - -#define _MBS_SUPPORT 0 - -#include "tsplitpath_s.inl" diff --git a/pal/src/safecrt/strtok_s.c b/pal/src/safecrt/strtok_s.c deleted file mode 100644 index 2622d0c1b45..00000000000 --- a/pal/src/safecrt/strtok_s.c +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*** -*strtok_s.c - tokenize a string with given delimiters -* - -* -*Purpose: -* defines strtok_s() - breaks string into series of token -* via repeated calls. -* -*******************************************************************************/ - -#include -#include -#include -#include "internal_securecrt.h" - -#include "mbusafecrt_internal.h" - -#define _FUNC_PROLOGUE -#define _FUNC_NAME strtok_s -#define _CHAR char - -#include "tcstok_s.inl" diff --git a/pal/src/safecrt/tsplitpath_s.inl b/pal/src/safecrt/tsplitpath_s.inl deleted file mode 100644 index 79e298e1e8d..00000000000 --- a/pal/src/safecrt/tsplitpath_s.inl +++ /dev/null @@ -1,281 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*** -*tsplitpath_s.inl - general implementation of _tsplitpath_s -* - -* -*Purpose: -* This file contains the general algorithm for _splitpath_s and its variants. -* -*******************************************************************************/ - -_FUNC_PROLOGUE -errno_t __cdecl _FUNC_NAME( - __in_z const _CHAR *_Path, - __out_ecount_z_opt(_DriveSize) _CHAR *_Drive, __in size_t _DriveSize, - __out_ecount_z_opt(_DirSize) _CHAR *_Dir, __in size_t _DirSize, - __out_ecount_z_opt(_FilenameSize) _CHAR *_Filename, __in size_t _FilenameSize, - __out_ecount_z_opt(_ExtSize) _CHAR *_Ext, __in 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 */ - if (_Path == NULL) - { - goto error_einval; - } - if ((_Drive == NULL && _DriveSize != 0) || (_Drive != NULL && _DriveSize == 0)) - { - goto error_einval; - } - if ((_Dir == NULL && _DirSize != 0) || (_Dir != NULL && _DirSize == 0)) - { - goto error_einval; - } - if ((_Filename == NULL && _FilenameSize != 0) || (_Filename != NULL && _FilenameSize == 0)) - { - goto error_einval; - } - if ((_Ext == NULL && _ExtSize != 0) || (_Ext != NULL && _ExtSize == 0)) - { - goto error_einval; - } - - /* check if _Path begins with the longpath prefix */ - if (_Path[0] == _T('\\') && _Path[1] == _T('\\') && _Path[2] == _T('?') && _Path[3] == _T('\\')) - { - _Path += 4; - } - - /* extract drive letter and ':', if any */ - if (!drive_set) - { -// The CorUnix PAL is never built on Windows and thus, the code below -// for the drive check is not required. -#if 0 - size_t skip = _MAX_DRIVE - 2; - tmp = _Path; - while (skip > 0 && *tmp != 0) - { - skip--; - tmp++; - } - if (*tmp == _T(':')) - { - if (_Drive != NULL) - { - if (_DriveSize < _MAX_DRIVE) - { - goto error_erange; - } - _TCSNCPY_S(_Drive, _DriveSize, _Path, _MAX_DRIVE - 1); - } - _Path = tmp + 1; - } - else -#endif - { - if (_Drive != NULL) - { - _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 = NULL; - dot = NULL; - tmp = _Path; - for (; *tmp != 0; ++tmp) - { -#if _MBS_SUPPORT -#pragma warning(push) -#pragma warning(disable:4127) - if (_ISMBBLEAD(*tmp)) -#pragma warning(pop) - { - tmp++; - } - else -#endif /* _MBS_SUPPORT */ - { - if (*tmp == _T('/') || *tmp == _T('\\')) - { - /* point to one beyond for later copy */ - last_slash = tmp + 1; - } - else if (*tmp == _T('.')) - { - dot = tmp; - } - } - } - - if (last_slash != NULL) - { - /* found a path - copy up through last_slash or max characters - * allowed, whichever is smaller - */ - if (_Dir != NULL) { - length = (size_t)(last_slash - _Path); - if (_DirSize <= length) - { - goto error_erange; - } - _TCSNCPY_S(_Dir, _DirSize, _Path, length); - - // Normalize the path seperator - int iIndex; - for(iIndex = 0; iIndex < length; iIndex++) - { - if (_Dir[iIndex] == _T('\\')) - { - _Dir[iIndex] = _T('/'); - } - } - } - _Path = last_slash; - } - else - { - /* there is no path */ - if (_Dir != NULL) - { - _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 != NULL && (dot >= _Path)) - { - /* found the marker for an extension - copy the file name up to the '.' */ - if (_Filename) - { - length = (size_t)(dot - _Path); - if (length == 0) - { - // At this time, dot will be equal to _Path if string is something like "/." - // since _path was set to last_slash, which in turn, was set to "tmp +1" - // where "tmp" is the location where "/" was found. See code above for - // clarification. - // - // For such cases, return the "." in filename buffer. - // - // Thus, if the length is zero, we know its a string like "/." and thus, we - // set length to 1 to get the "." in filename buffer. - length = 1; - } - - if (_FilenameSize <= length) - { - goto error_erange; - } - _TCSNCPY_S(_Filename, _FilenameSize, _Path, length); - } - - /* now we can get the extension - remember that tmp still points - * to the terminating NULL character of path. - */ - if (_Ext) - { - // At this time, _Path is pointing to the character after the last slash found. - // (See comments and code above for clarification). - // - // Returns extension as empty string for strings like "/.". - if (dot > _Path) - { - length = (size_t)(tmp - dot); - if (_ExtSize <= length) - { - goto error_erange; - } - - /* Since dot pointed to the ".", make sure we actually have an extension - like ".cmd" and not just ".", OR - - Confirm that its a string like "/.." - for this, return the - second "." in the extension part. - - However, for strings like "/myfile.", return empty string - in extension buffer. - */ - int fIsDir = (*(dot-1) == _T('.'))?1:0; - if (length > 1 || (length == 1 && fIsDir == 1)) - _TCSNCPY_S(_Ext, _ExtSize, dot, length); - else - _RESET_STRING(_Ext, _ExtSize); - } - else - _RESET_STRING(_Ext, _ExtSize); - } - } - 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; - } - _TCSNCPY_S(_Filename, _FilenameSize, _Path, length); - } - if (_Ext) - { - _RESET_STRING(_Ext, _ExtSize); - } - } - - _RETURN_NO_ERROR; - -error_einval: - bEinval = 1; - -error_erange: - if (_Drive != NULL && _DriveSize > 0) - { - _RESET_STRING(_Drive, _DriveSize); - } - if (_Dir != NULL && _DirSize > 0) - { - _RESET_STRING(_Dir, _DirSize); - } - if (_Filename != NULL && _FilenameSize > 0) - { - _RESET_STRING(_Filename, _FilenameSize); - } - if (_Ext != NULL && _ExtSize > 0) - { - _RESET_STRING(_Ext, _ExtSize); - } - - _VALIDATE_POINTER(_Path); - if (bEinval) - { - _RETURN_EINVAL; - } - return (errno = ERANGE); -} diff --git a/pal/src/safecrt/vswprint.c b/pal/src/safecrt/vswprint.c deleted file mode 100644 index 0fc71bbb2b3..00000000000 --- a/pal/src/safecrt/vswprint.c +++ /dev/null @@ -1,283 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*** -*vswprint.c - print formatted data into a string from var arg list -* -*Purpose: -* defines vswprintf(), _vswprintf_c and _vsnwprintf() - print formatted output to -* a string, get the data from an argument ptr instead of explicit -* arguments. -* -*******************************************************************************/ - - -#include -#include -#include -#include "internal_securecrt.h" - -#include "mbusafecrt_internal.h" - -typedef int (*WOUTPUTFN)(miniFILE *, const char16_t *, va_list); - -static int _vswprintf_helper( WOUTPUTFN outfn, char16_t *string, size_t count, const char16_t *format, va_list ap ); -static int _vscwprintf_helper (WOUTPUTFN outfn, const char16_t *format, va_list ap ); - -/*** -*ifndef _COUNT_ -*int _vswprintf(string, format, ap) - print formatted data to string from arg ptr -*else -*ifndef _SWPRINTFS_ERROR_RETURN_FIX -*int _vsnwprintf(string, cnt, format, ap) - print formatted data to string from arg ptr -*else -*int _vswprintf_c(string, cnt, format, ...) - print formatted data to string -*endif -*endif -* -*Purpose: -* Prints formatted data, but to a string and gets data from an argument -* pointer. -* Sets up a FILE so file i/o operations can be used, make string look -* like a huge buffer to it, but _flsbuf will refuse to flush it if it -* fills up. Appends '\0' to make it a true string. -* -* Allocate the 'fake' _iob[] entryit statically instead of on -* the stack so that other routines can assume that _iob[] entries are in -* are in DGROUP and, thus, are near. -* -*ifdef _COUNT_ -*ifndef _SWPRINTFS_ERROR_RETURN_FIX -* The _vsnwprintf() flavor takes a count argument that is -* the max number of bytes that should be written to the -* user's buffer. -* We don't expose this function directly in the headers. -*else -* The _vswprintf_c() flavor does the same thing as the _snwprintf -* above, but, it also fixes an issue in the return value in the case -* when there isn't enough space to write the null terminator -* We don't fix this issue in _vsnwprintf because of backward -* compatibility. In new code, however, _vsnwprintf is #defined to -* _vswprintf_c so users get the fix. -* -*endif -* -* Multi-thread: (1) Since there is no stream, this routine must never try -* to get the stream lock (i.e., there is no stream lock either). (2) -* Also, since there is only one statically allocated 'fake' iob, we must -* lock/unlock to prevent collisions. -* -*Entry: -* char16_t *string - place to put destination string -*ifdef _COUNT_ -* size_t count - max number of bytes to put in buffer -*endif -* char16_t *format - format string, describes format of data -* va_list ap - varargs argument pointer -* -*Exit: -* returns number of wide characters in string -* returns -2 if the string has been truncated (only in _vsnprintf_helper) -* returns -1 in other error cases -* -*Exceptions: -* -*******************************************************************************/ - -int __cdecl _vswprintf_helper ( - WOUTPUTFN woutfn, - char16_t *string, - size_t count, - const char16_t *format, - va_list ap - ) -{ - miniFILE str; - miniFILE *outfile = &str; - int retval; - - _VALIDATE_RETURN( (format != NULL), EINVAL, -1); - - _VALIDATE_RETURN( (count == 0) || (string != NULL), EINVAL, -1 ); - - outfile->_flag = _IOWRT|_IOSTRG; - outfile->_ptr = outfile->_base = (char *) string; - - if(count>(INT_MAX/sizeof(char16_t))) - { - /* old-style functions allow any large value to mean unbounded */ - outfile->_cnt = INT_MAX; - } - else - { - outfile->_cnt = (int)(count*sizeof(char16_t)); - } - - retval = woutfn(outfile, format, ap ); - - if(string==NULL) - { - return retval; - } - - if((retval >= 0) && (_putc_nolock('\0',outfile) != EOF) && (_putc_nolock('\0',outfile) != EOF)) - return(retval); - - string[count - 1] = 0; - if (outfile->_cnt < 0) - { - /* the buffer was too small; we return -2 to indicate truncation */ - return -2; - } - return -1; -} - -int __cdecl _vswprintf_s ( - char16_t *string, - size_t sizeInWords, - const char16_t *format, - va_list ap - ) -{ - int retvalue = -1; - - /* validation section */ - _VALIDATE_RETURN(format != NULL, EINVAL, -1); - _VALIDATE_RETURN(string != NULL && sizeInWords > 0, EINVAL, -1); - - retvalue = _vswprintf_helper(_woutput_s, string, sizeInWords, format, ap); - if (retvalue < 0) - { - string[0] = 0; - _SECURECRT__FILL_STRING(string, sizeInWords, 1); - } - if (retvalue == -2) - { - _VALIDATE_RETURN(("Buffer too small" && 0), ERANGE, -1); - } - if (retvalue >= 0) - { - _SECURECRT__FILL_STRING(string, sizeInWords, retvalue + 1); - } - - return retvalue; -} - -int __cdecl _vsnwprintf_s ( - char16_t *string, - size_t sizeInWords, - size_t count, - const char16_t *format, - va_list ap - ) -{ - int retvalue = -1; - errno_t save_errno = 0; - - /* validation section */ - _VALIDATE_RETURN(format != NULL, EINVAL, -1); - if (count == 0 && string == NULL && sizeInWords == 0) - { - /* this case is allowed; nothing to do */ - return 0; - } - _VALIDATE_RETURN(string != NULL && sizeInWords > 0, EINVAL, -1); - - if (sizeInWords > count) - { - save_errno = errno; - retvalue = _vswprintf_helper(_woutput_s, string, count + 1, format, ap); - if (retvalue == -2) - { - /* the string has been truncated, return -1 */ - _SECURECRT__FILL_STRING(string, sizeInWords, count + 1); - if (errno == ERANGE) - { - errno = save_errno; - } - return -1; - } - } - else /* sizeInWords <= count */ - { - save_errno = errno; - retvalue = _vswprintf_helper(_woutput_s, string, sizeInWords, format, ap); - string[sizeInWords - 1] = 0; - /* we allow truncation if count == _TRUNCATE */ - if (retvalue == -2 && count == _TRUNCATE) - { - if (errno == ERANGE) - { - errno = save_errno; - } - return -1; - } - } - - if (retvalue < 0) - { - string[0] = 0; - _SECURECRT__FILL_STRING(string, sizeInWords, 1); - if (retvalue == -2) - { - _VALIDATE_RETURN(("Buffer too small" && 0), ERANGE, -1); - } - return -1; - } - - _SECURECRT__FILL_STRING(string, sizeInWords, retvalue + 1); - - return (retvalue < 0 ? -1 : retvalue); -} - -/*** -* _vscwprintf() - counts the number of character needed to print the formatted -* data -* -*Purpose: -* Counts the number of characters in the fotmatted data. -* -*Entry: -* char16_t *format - format string, describes format of data -* va_list ap - varargs argument pointer -* -*Exit: -* returns number of characters needed to print formatted data. -* -*Exceptions: -* -*******************************************************************************/ - -#ifndef _COUNT_ - -int __cdecl _vscwprintf_helper ( - WOUTPUTFN woutfn, - const char16_t *format, - va_list ap - ) -{ - miniFILE str; - miniFILE *outfile = &str; - int retval; - - _VALIDATE_RETURN( (format != NULL), EINVAL, -1); - - outfile->_cnt = INT_MAX; //MAXSTR; - outfile->_flag = _IOWRT|_IOSTRG; - outfile->_ptr = outfile->_base = NULL; - - retval = woutfn(outfile, format, ap); - return(retval); -} - -int __cdecl _vscwprintf ( - const char16_t *format, - va_list ap - ) -{ - return _vscwprintf_helper(_woutput_s, format, ap); -} - -#endif /* _COUNT_ */ diff --git a/pal/src/safecrt/wmakepath_s.c b/pal/src/safecrt/wmakepath_s.c deleted file mode 100644 index dab5af010a7..00000000000 --- a/pal/src/safecrt/wmakepath_s.c +++ /dev/null @@ -1,31 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*** -*wmakepath_s.c - create path name from components -* - -* -*Purpose: -* To provide support for creation of full path names from components -* -*******************************************************************************/ - -#include -#include -#include -#include "internal_securecrt.h" - -#include "mbusafecrt_internal.h" - -#define _FUNC_PROLOGUE -#define _FUNC_NAME _wmakepath_s -#define _CHAR char16_t -#define _DEST _Dst -#define _SIZE _SizeInWords -#define _T(_Character) L##_Character -#define _MBS_SUPPORT 0 - -#include "tmakepath_s.inl" diff --git a/pal/src/safecrt/wsplitpath_s.c b/pal/src/safecrt/wsplitpath_s.c deleted file mode 100644 index 46bb0feb989..00000000000 --- a/pal/src/safecrt/wsplitpath_s.c +++ /dev/null @@ -1,31 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*** -*wsplitpath_s.c - break down path name into components -* - -* -*Purpose: -* To provide support for accessing the individual components of an -* arbitrary path name -* -*******************************************************************************/ - -#include -#include -#include -#include "internal_securecrt.h" - -#include "mbusafecrt_internal.h" - -#define _FUNC_PROLOGUE -#define _FUNC_NAME _wsplitpath_s -#define _CHAR char16_t -#define _TCSNCPY_S wcsncpy_s -#define _T(_Character) L##_Character -#define _MBS_SUPPORT 0 - -#include "tsplitpath_s.inl"