Beispiel #1
0
void SHVConsole::fwprintf(FILE* f, const WCHAR* str, ...)
{
SHVVA_LIST args;
	SHVVA_START(args,str);
	vfwprintf(f,str,args);
	SHVVA_END(args);
}
Beispiel #2
0
static void cvt_wprintf(FILE *dest,const wchar *fmt,va_list arglist)
{
  // This buffer is for format string only, not for entire output,
  // so it can be short enough.
  wchar fmtw[1024];
  PrintfPrepareFmt(fmt,fmtw,ASIZE(fmtw));
#ifdef _WIN_ALL
  safebuf wchar Msg[MaxMsgSize];
  if (dest==stdout && StdoutRedirected || dest==stderr && StderrRedirected)
  {
    // Avoid Unicode for redirect in Windows, it does not work with pipes.
    vswprintf(Msg,ASIZE(Msg),fmtw,arglist);
    safebuf char MsgA[MaxMsgSize];
    WideToChar(Msg,MsgA,ASIZE(MsgA));
    CharToOemA(MsgA,MsgA); // Console tools like 'more' expect OEM encoding.

    // We already converted \n to \r\n above, so we use WriteFile instead
    // of C library to avoid unnecessary additional conversion.
    HANDLE hOut=GetStdHandle(dest==stdout ? STD_OUTPUT_HANDLE:STD_ERROR_HANDLE);
    DWORD Written;
    WriteFile(hOut,MsgA,(DWORD)strlen(MsgA),&Written,NULL);
    return;
  }
  // MSVC2008 vfwprintf writes every character to console separately
  // and it is too slow. We use direct WriteConsole call instead.
  vswprintf(Msg,ASIZE(Msg),fmtw,arglist);
  HANDLE hOut=GetStdHandle(dest==stderr ? STD_ERROR_HANDLE:STD_OUTPUT_HANDLE);
  DWORD Written;
  WriteConsole(hOut,Msg,(DWORD)wcslen(Msg),&Written,NULL);
#else
  vfwprintf(dest,fmtw,arglist);
  // We do not use setbuf(NULL) in Unix (see comments in InitConsole).
  fflush(dest);
#endif
}
Beispiel #3
0
void kprintf(PCWCHAR format, ...)
{
#ifdef _WINDLL
	int varBuf;
	size_t tempSize;
#endif
	va_list args;
	va_start(args, format);
#ifndef _WINDLL
	vwprintf(format, args);
	fflush(stdout);
#else
	if(outputBuffer)
	{
		varBuf = _vscwprintf(format, args);
		if(varBuf > 0)
		{
			if((size_t) varBuf > (outputBufferElements - outputBufferElementsPosition - 1)) // NULL character
			{
				tempSize = (outputBufferElements + varBuf + 1) * 2; // * 2, just to be cool
				if(outputBuffer = (wchar_t *) LocalReAlloc(outputBuffer, tempSize * sizeof(wchar_t), LMEM_MOVEABLE))
					outputBufferElements = tempSize;
			}
			varBuf = vswprintf_s(outputBuffer + outputBufferElementsPosition, outputBufferElements - outputBufferElementsPosition, format, args);
			if(varBuf > 0)
				outputBufferElementsPosition += varBuf;
		}
	}
#endif
	if(logfile)
		vfwprintf(logfile, format, args);
	va_end(args);
	fflush(logfile);
}
Beispiel #4
0
void
tzf_logger_t::Log   (_In_z_ _Printf_format_string_
                      wchar_t const* const _Format, ...)
{
  va_list _ArgList;

  if (! initialized)
    return;

  EnterCriticalSection (&log_mutex);

  if ((! fLog) || silent) {
    LeaveCriticalSection (&log_mutex);
    return;
  }

  wchar_t wszLogTime [128];

  WORD ms = TZF_Timestamp (wszLogTime);

  fwprintf (fLog, L"%s%03u: ", wszLogTime, ms);

  va_start (_ArgList, _Format);
  {
    vfwprintf (fLog, _Format, _ArgList);
  }
  va_end   (_ArgList);

  fwprintf  (fLog, L"\n");
  fflush    (fLog);

  LeaveCriticalSection (&log_mutex);
}
Beispiel #5
0
 void report(const char* modName, Level severity,
             const wchar_t* format, va_list ap)
 {
     _reportHead(modName, nullptr, severity);
     vfwprintf(stderr, format, ap);
     fprintf(stderr, "\n");
 }
Beispiel #6
0
void PdfError::LogMessageInternal( ELogSeverity eLogSeverity, const wchar_t* pszMsg, va_list & args )
{
    const wchar_t* pszPrefix = NULL;

    switch( eLogSeverity ) 
    {
        case eLogSeverity_Error:
            break;
        case eLogSeverity_Critical:
	    pszPrefix = L"CRITICAL: ";
            break;
        case eLogSeverity_Warning:
	    pszPrefix = L"WARNING: ";
            break;
	case eLogSeverity_Information:
            break;
	case eLogSeverity_Debug:
	    pszPrefix = L"DEBUG: ";
            break;
	case eLogSeverity_None:
	case eLogSeverity_Unknown:
        default:
            break;
    }

    if( pszPrefix )
        fwprintf( stderr, pszPrefix );

    vfwprintf( stderr, pszMsg, args );
}
Beispiel #7
0
int
vswprintf(wchar_t* s, size_t n, const wchar_t* fmt, va_list args)
{
	Sfio_t	f;
	int	v;

	if (!s)
		return -1;

	/*
	 * make a fake stream
	 */

	SFCLEAR(&f, NiL);
	f.flags = SF_STRING|SF_WRITE;
	f.bits = SF_PRIVATE;
	f.mode = SF_WRITE;
	f.size = n - 1;
	f.data = f.next = f.endr = (uchar*)s;
	f.endb = f.endw = f.data + f.size;

	/*
	 * call and adjust
	 */

	v = vfwprintf(&f, fmt, args);
	*f.next = 0;
	_Sfi = f.next - f.data;
	return v;
}
Beispiel #8
0
DLL_EXPORTED
int
libintl_vfwprintf (FILE *stream, const wchar_t *format, va_list args)
{
  if (wcschr (format, '$') == NULL)
    return vfwprintf (stream, format, args);
  else
    {
      size_t length;
      wchar_t *result = libintl_vasnwprintf (NULL, &length, format, args);
      int retval = -1;
      if (result != NULL)
        {
          size_t i;
          for (i = 0; i < length; i++)
            if (fputwc (result[i], stream) == WEOF)
              break;
          free (result);
          if (i == length)
            {
              if (length > INT_MAX)
                errno = EOVERFLOW;
              else
                retval = length;
            }
        }
      return retval;
    }
}
Beispiel #9
0
int fwprintf(FILE* stream, const wchar_t* format, ...) {
  va_list args;
  va_start(args, format);
  int result = vfwprintf(stream, format, args);
  va_end(args);
  return result;
}
__inline void TraceW(const wchar_t *format, ...)
{
	if(g_bDebug)
	{
		if (format)
		{
			va_list arglist;
			wchar_t str[4096];

			va_start(arglist, format);
			if (g_fLogFile)
			{
				FILE *fout = fopen(g_fLogFile, "a+t");
				if (fout)
				{
					vfwprintf(fout, format, arglist);
					fclose(fout);
				}
			}
			
			StringCchVPrintfW(str, 4096, format, arglist);
			wprintf(str);
			
			if (g_bDebugString)
			{				
				OutputDebugStringW(str);
			}

			va_end(arglist);
		}
	}
}
Beispiel #11
0
void WriteWideFormatted (FILE * stream, const wchar_t * format, ...)
{
  va_list args;
  va_start (args, format);
  vfwprintf (stream, format, args);
  va_end (args);
}
Beispiel #12
0
int
__fxprintf (FILE *fp, const char *fmt, ...)
{
  if (fp == NULL)
    fp = stderr;

  va_list ap;
  va_start (ap, fmt);

  int res;
  if (fwide (fp, 0) > 0)
    {
      size_t len = strlen (fmt) + 1;
      wchar_t wfmt[len];
      for (size_t i = 0; i < len; ++i)
	{
	  assert (isascii (fmt[i]));
	  wfmt[i] = fmt[i];
	}
      res = vfwprintf (fp, wfmt, ap);
    }
  else
    res = INTUSE(vfprintf) (fp, fmt, ap);

  va_end (ap);

  return res;
}
Beispiel #13
0
// Diagnostic logging
SBTRDUTIL_API_CLASS void
SBtrdEvent::Diag (VXIunsigned tag, const VXIchar *subtag, 
		  const VXIchar *format, ...) const
{
  if ( _log ) {
    if ( format ) {
      va_list arguments;
      va_start(arguments, format);
      (*_log->VDiagnostic)(_log, tag + _diagTagBase, subtag, format, 
			   arguments);
      va_end(arguments);
    } else {
      (*_log->Diagnostic)(_log, tag + _diagTagBase, subtag, NULL);
    }
#if 0
  } else {
    VXIchar temp[1024];
    va_list arguments;
    va_start(arguments, format);
    wcscpy (temp, subtag);
    wcscat (temp, L"|");
    wcscat (temp, format);
    wcscat (temp, L"\n");
    vfwprintf(stderr, temp, arguments);
    va_end(arguments);
#endif
  }
}
Beispiel #14
0
BOOL ATEFile::VPrintf(const WCHAR* pszFormat, va_list arg)
{
    if(NULL == pszFormat) { return FALSE; }
    
    INT32 nRet = vfwprintf(m_pFile, pszFormat, arg);
    if(0 != fflush(m_pFile)) { return FALSE; }
    return (nRet < 0 ? FALSE : TRUE);
}
Beispiel #15
0
void msgff(DWORD ErrorCode, LPCWSTR Format, ...)
{
	va_list ap;
	va_start(ap, Format);
	vfwprintf(stdout, Format, ap);
	va_end(ap);
	report_error(stdout, ErrorCode);
}
Beispiel #16
0
int vfwprintfDotsShell( FILE * stream, const wchar_t * format, ... ) {
    int res;
    va_list argList;
    va_start( argList, format );
    res = vfwprintf( stream, format, argList );
    va_end( argList );
    return res;
}
Beispiel #17
0
void kprintf_inputline(PCWCHAR format, ...)
{
	va_list args;
	va_start(args, format);
	if(logfile)
		vfwprintf(logfile, format, args);
	va_end(args);
	fflush(logfile);
}
Beispiel #18
0
int fwprintf(FILE *f, const wchar_t *fmt, ...)
{
	int ret;
	va_list ap;
	va_start(ap, fmt);
	ret = vfwprintf(f, fmt, ap);
	va_end(ap);
	return ret;
}
Beispiel #19
0
void terminate(wchar_t *message, ...) {
    va_list argptr;
    va_start(argptr, message);
    vfwprintf(stderr, message, argptr);
    va_end(argptr);
    fwprintf(stderr, L"\n");

    exit(1);
}
Beispiel #20
0
 void report(const char* modName, Level severity,
             const wchar_t* format, va_list ap)
 {
     openFile();
     _reportHead(modName, nullptr, severity);
     vfwprintf(fp, format, ap);
     fprintf(fp, "\n");
     closeFile();
 }
static void badVaSinkB(wchar_t * data, ...)
{
    {
        va_list args;
        va_start(args, data);
        /* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
        vfwprintf(stdout, data, args);
        va_end(args);
    }
}
static void goodB2GVaSinkG(wchar_t * data, ...)
{
    {
        va_list args;
        va_start(args, data);
        /* FIX: Specify the format disallowing a format string vulnerability */
        vfwprintf(stdout, L"%s", args);
        va_end(args);
    }
}
Beispiel #23
0
/*
 * This takes strings from a resource stringtable
 * and outputs it to the console.
 */
VOID PrintResourceString(INT resID, ...)
{
    WCHAR tmpBuffer[MAX_BUFFER_SIZE];
    va_list arg_ptr;

    va_start(arg_ptr, resID);
    LoadStringW(GetModuleHandle(NULL), resID, tmpBuffer, MAX_BUFFER_SIZE);
    vfwprintf(stdout, tmpBuffer, arg_ptr);
    va_end(arg_ptr);
}
Beispiel #24
0
void Helpers::LogError(__in __nullterminated const char16 *msg, ...)
{
    va_list args;
    va_start(args, msg);
    wprintf(_u("ERROR: "));
    vfwprintf(stderr, msg, args);
    wprintf(_u("\n"));
    fflush(stdout);
    va_end(args);
}
Beispiel #25
0
 void reportSource(const char* modName, Level severity,
                   const char* file, unsigned linenum,
                   const wchar_t* format, va_list ap)
 {
     char sourceInfo[128];
     snprintf(sourceInfo, 128, "%s:%u", file, linenum);
     _reportHead(modName, sourceInfo, severity);
     vfwprintf(stderr, format, ap);
     fprintf(stderr, "\n");
 }
static void
debug(wchar_t* format, ...)
{
    if (debug_fp != NULL) {
        va_list ap;
        va_start(ap, format);
        vfwprintf(debug_fp, format, ap);
        va_end(ap);
    }
}
Beispiel #27
0
int
wprintf(const wchar_t* fmt, ...)
{
	va_list	args;
	int	v;

	va_start(args, fmt);
	v = vfwprintf(sfstdout, fmt, args);
	va_end(args);
	return v;
}
Beispiel #28
0
void klog(FILE * logfile, PCWCHAR format, ...)
{
	if(logfile)
	{
		va_list args;
		va_start(args, format);
		vfwprintf(logfile, format, args);
		va_end(args);
		fflush(logfile);
	}
}
Beispiel #29
0
int
fwprintf(Sfio_t* f, const wchar_t* fmt, ...)
{
	va_list	args;
	int	v;

	va_start(args, fmt);
	v = vfwprintf(f, fmt, args);
	va_end(args);
	return v;
}
Beispiel #30
0
BOOL ATEFile::Printf(const WCHAR* pszFormat, ...)
{
    if(NULL == pszFormat) { return FALSE; }
    va_list arg;
    va_start(arg, pszFormat);
    INT32 nRet = vfwprintf(m_pFile, pszFormat, arg);
    va_end(arg);

    if(0 != fflush(m_pFile)) { return FALSE; }
    return (nRet < 0 ? FALSE : TRUE);
}