summaryrefslogtreecommitdiff
path: root/src/pal/src/cruntime/silent_printf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/src/cruntime/silent_printf.cpp')
-rw-r--r--src/pal/src/cruntime/silent_printf.cpp280
1 files changed, 0 insertions, 280 deletions
diff --git a/src/pal/src/cruntime/silent_printf.cpp b/src/pal/src/cruntime/silent_printf.cpp
index 1d10963..4047c7e 100644
--- a/src/pal/src/cruntime/silent_printf.cpp
+++ b/src/pal/src/cruntime/silent_printf.cpp
@@ -40,286 +40,6 @@ static INT Silent_AddPaddingVfprintf(PAL_FILE *stream, LPSTR In, INT Padding,
static size_t Silent_PAL_wcslen(const wchar_16 *string);
-/*******************************************************************************
-Function:
- PAL_vsnprintf (silent version)
- for more details, see PAL_vsnprintf in printf.c
-*******************************************************************************/
-INT Silent_PAL_vsnprintf(LPSTR Buffer, INT Count, LPCSTR Format, va_list aparg)
-{
- BOOL BufferRanOut = FALSE;
- CHAR TempBuff[1024]; /* used to hold a single %<foo> format string */
- LPSTR BufferPtr = Buffer;
- LPCSTR Fmt = Format;
- LPWSTR TempWStr;
- CHAR TempStr[MAX_STR_LEN+1];
- WCHAR TempWChar;
- INT Flags;
- INT Width;
- INT Precision;
- INT Prefix;
- INT Type;
- INT Length;
- INT TempInt;
- int wctombResult;
- va_list ap;
-
- va_copy(ap, aparg);
-
- while (*Fmt)
- {
- if ((BufferPtr - Buffer) >= Count)
- {
- BufferRanOut = TRUE;
- break;
- }
- else if(*Fmt == '%' &&
- TRUE == Silent_ExtractFormatA(&Fmt, TempBuff, &Flags,
- &Width, &Precision,
- &Prefix, &Type))
- {
- if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_STRING)
- {
- if (WIDTH_STAR == Width)
- {
- Width = va_arg(ap, INT);
- }
- else if (WIDTH_INVALID == Width)
- {
- /* both a '*' and a number, ignore, but remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- if (PRECISION_STAR == Precision)
- {
- Precision = va_arg(ap, INT);
- }
- else if (PRECISION_INVALID == Precision)
- {
- /* both a '*' and a number, ignore, but remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- TempWStr = va_arg(ap, LPWSTR);
- Length = Silent_WideCharToMultiByte(TempWStr, -1, 0, 0);
- if (!Length)
- {
- va_end(ap);
- return -1;
- }
-
- /* clip string output to MAX_STR_LEN characters */
- if (PRECISION_DOT == Precision)
- {
- Precision = MAX_STR_LEN;
- }
-
- if (PRECISION_DOT == Precision)
- {
- /* copy nothing */
- *TempStr = 0;
- Length = 0;
- }
- else if (Precision > 0 && Precision < Length - 1)
- {
- Length = Silent_WideCharToMultiByte(TempWStr, Precision,
- TempStr, Length);
- if (!Length)
- {
- va_end(ap);
- return -1;
- }
- TempStr[Length] = 0;
- Length = Precision;
- }
- /* copy everything */
- else
- {
- wctombResult = Silent_WideCharToMultiByte(TempWStr, -1,
- TempStr, Length);
- if (!wctombResult)
- {
- PAL_free(TempStr);
- va_end(ap);
- return -1;
- }
- --Length; /* exclude null char */
- }
-
- /* do the padding (if needed)*/
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- TempStr,
- Width - Length,
- Flags);
- }
- else if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_CHAR)
- {
- CHAR TempBuffer[4];
-
- if (WIDTH_STAR == Width ||
- WIDTH_INVALID == Width)
- {
- /* ignore (because it's a char), and remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
- if (PRECISION_STAR == Precision ||
- PRECISION_INVALID == Precision)
- {
- /* ignore (because it's a char), and remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- TempWChar = va_arg(ap, int);
- Length = Silent_WideCharToMultiByte(&TempWChar, 1, TempBuffer, 4);
- if (!Length)
- {
- va_end(ap);
- return -1;
- }
- TempBuffer[Length] = 0;
-
- /* do the padding (if needed)*/
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- TempBuffer,
- Width - Length,
- Flags);
-
- }
- /* this places the number of bytes written to the buffer in the
- next arg */
- else if (Type == PFF_TYPE_N)
- {
- if (WIDTH_STAR == Width)
- {
- Width = va_arg(ap, INT);
- }
- if (PRECISION_STAR == Precision)
- {
- Precision = va_arg(ap, INT);
- }
- if (Prefix == PFF_PREFIX_SHORT)
- {
- *(va_arg(ap, short *)) = BufferPtr - Buffer;
- }
- else
- {
- *(va_arg(ap, LPLONG)) = BufferPtr - Buffer;
- }
- }
- else if (Type == PFF_TYPE_CHAR && (Flags & PFF_ZERO) != 0)
- {
- // Some versions of sprintf don't support 0-padded chars,
- // so we handle them here.
- char ch[2];
-
- ch[0] = (char) va_arg(ap, int);
- ch[1] = '\0';
- Length = 1;
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- ch,
- Width - Length,
- Flags);
- }
- else if (Type == PFF_TYPE_STRING && (Flags & PFF_ZERO) != 0)
- {
- // Some versions of sprintf don't support 0-padded strings,
- // so we handle them here.
- char *tempStr;
-
- tempStr = va_arg(ap, char *);
- Length = strlen(tempStr);
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- tempStr,
- Width - Length,
- Flags);
- }
- /* types that sprintf can handle */
- else
- {
- size_t TempCount = Count - (BufferPtr - Buffer);
-
- TempInt = 0;
- /* %h (short) doesn't seem to be handled properly by local sprintf,
- so lets do the truncation ourselves. (ptr -> int -> short to avoid
- warnings */
- if (Type == PFF_TYPE_P && Prefix == PFF_PREFIX_SHORT)
- {
- long trunc1;
- short trunc2;
-
- trunc1 = va_arg(ap, LONG);
- trunc2 = (short)trunc1;
-
- TempInt = snprintf(BufferPtr, TempCount, TempBuff, trunc2);
- }
- else if (Type == PFF_TYPE_INT && Prefix == PFF_PREFIX_SHORT)
- {
- // Convert explicitly from int to short to get
- // correct sign extension for shorts on all systems.
- int n;
- short s;
-
- n = va_arg(ap, int);
- s = (short) n;
-
- TempInt = snprintf(BufferPtr, TempCount, TempBuff, s);
- }
- else
- {
- /* limit string output (%s) to 300 characters */
- if(TempBuff[0] == '%' && TempBuff[1] == 's')
- {
- if (strcpy_s(TempBuff, sizeof(TempBuff), "%.300s") != SAFECRT_SUCCESS)
- {
- va_end(ap);
- return -1;
- }
- }
- va_list apcopy;
- va_copy(apcopy, ap);
- TempInt = InternalVsnprintf(CorUnix::InternalGetCurrentThread(), BufferPtr, TempCount, TempBuff, apcopy);
- va_end(apcopy);
- PAL_printf_arg_remover(&ap, Width, Precision, Type, Prefix);
- }
-
- if (TempInt < 0 || static_cast<size_t>(TempInt) >= TempCount) /* buffer not long enough */
- {
- BufferPtr += TempCount;
- BufferRanOut = TRUE;
- }
- else
- {
- BufferPtr += TempInt;
- }
- }
- }
- else
- {
- *BufferPtr++ = *Fmt++; /* copy regular chars into buffer */
- }
- }
-
- if (Count > (BufferPtr - Buffer))
- {
- *BufferPtr = 0; /* end the string */
- }
-
- va_end(ap);
-
- if (BufferRanOut)
- {
- return -1;
- }
- else
- {
- return BufferPtr - Buffer;
- }
-}
-
/*++
Function:
PAL_vfprintf (silent version)