Module: wine Branch: master Commit: 1eaae093e294fff3174f616d44b686af1be99965 URL: http://source.winehq.org/git/wine.git/?a=commit;h=1eaae093e294fff3174f616d44...
Author: Eric Pouech eric.pouech@orange.fr Date: Sun Nov 7 19:11:38 2010 +0100
msvcrt: Implemented _vc(w)printf.
---
dlls/msvcr100/msvcr100.spec | 6 +- dlls/msvcr70/msvcr70.spec | 2 +- dlls/msvcr71/msvcr71.spec | 2 +- dlls/msvcr80/msvcr80.spec | 6 +- dlls/msvcr90/msvcr90.spec | 6 +- dlls/msvcrt/console.c | 95 ++++++++++++++++++++++++++++++++++--------- dlls/msvcrt/msvcrt.spec | 6 +- 7 files changed, 89 insertions(+), 34 deletions(-)
diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec index 0a608b5..f172f7b 100644 --- a/dlls/msvcr100/msvcr100.spec +++ b/dlls/msvcr100/msvcr100.spec @@ -564,7 +564,7 @@ @ cdecl _ctime64(ptr) msvcrt._ctime64 @ stub _ctime64_s @ cdecl _cwait(ptr long long) msvcrt._cwait -@ stub _cwprintf +@ varargs _cwprintf(wstr) msvcrt._cwprintf @ stub _cwprintf_l @ stub _cwprintf_p @ stub _cwprintf_p_l @@ -1216,13 +1216,13 @@ @ cdecl _unlock_file(ptr) msvcrt._unlock_file @ cdecl _utime32(str ptr) msvcrt._utime32 @ cdecl _utime64(str ptr) msvcrt._utime64 -@ stub _vcprintf +@ cdecl _vcprintf(str ptr) msvcrt._vcprintf @ stub _vcprintf_l @ stub _vcprintf_p @ stub _vcprintf_p_l @ stub _vcprintf_s @ stub _vcprintf_s_l -@ stub _vcwprintf +@ cdecl _vcwprintf(wstr ptr) msvcrt._vcwprintf @ stub _vcwprintf_l @ stub _vcwprintf_p @ stub _vcwprintf_p_l diff --git a/dlls/msvcr70/msvcr70.spec b/dlls/msvcr70/msvcr70.spec index 307ae09..eaaf4f1 100644 --- a/dlls/msvcr70/msvcr70.spec +++ b/dlls/msvcr70/msvcr70.spec @@ -267,7 +267,7 @@ @ cdecl _ctime64(ptr) msvcrt._ctime64 @ extern _ctype msvcrt._ctype @ cdecl _cwait(ptr long long) msvcrt._cwait -@ stub _cwprintf +@ varargs _cwprintf(str) msvcrt._cwprintf @ varargs _cwscanf(wstr) msvcrt._cwscanf @ extern _daylight msvcrt._daylight @ extern _dstbias msvcrt._dstbias diff --git a/dlls/msvcr71/msvcr71.spec b/dlls/msvcr71/msvcr71.spec index fc8491d..e4f1a20 100644 --- a/dlls/msvcr71/msvcr71.spec +++ b/dlls/msvcr71/msvcr71.spec @@ -261,7 +261,7 @@ @ varargs _cscanf(str) msvcrt._cscanf @ cdecl _ctime64(ptr) msvcrt._ctime64 @ cdecl _cwait(ptr long long) msvcrt._cwait -@ stub _cwprintf +@ varargs _cwprintf(wstr) msvcrt._cwprintf @ varargs _cwscanf(wstr) msvcrt._cwscanf @ extern _daylight msvcrt._daylight @ extern _dstbias msvcrt._dstbias diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec index d29fad1..f939329 100644 --- a/dlls/msvcr80/msvcr80.spec +++ b/dlls/msvcr80/msvcr80.spec @@ -403,7 +403,7 @@ @ cdecl _ctime64(ptr) msvcrt._ctime64 @ stub _ctime64_s @ cdecl _cwait(ptr long long) msvcrt._cwait -@ stub _cwprintf +@ varargs _cwprintf(wstr) msvcrt._cwprintf @ stub _cwprintf_l @ stub _cwprintf_p @ stub _cwprintf_p_l @@ -1069,13 +1069,13 @@ @ cdecl _unlock_file(ptr) msvcrt._unlock_file @ cdecl _utime32(str ptr) msvcrt._utime32 @ cdecl _utime64(str ptr) msvcrt._utime64 -@ stub _vcprintf +@ cdecl _vcprintf(str ptr) msvcrt._vcprintf @ stub _vcprintf_l @ stub _vcprintf_p @ stub _vcprintf_p_l @ stub _vcprintf_s @ stub _vcprintf_s_l -@ stub _vcwprintf +@ cdecl _vcwprintf(wstr ptr) msvcrt._vcwprintf @ stub _vcwprintf_l @ stub _vcwprintf_p @ stub _vcwprintf_p_l diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec index cc822da..99e81fd 100644 --- a/dlls/msvcr90/msvcr90.spec +++ b/dlls/msvcr90/msvcr90.spec @@ -395,7 +395,7 @@ @ cdecl _ctime64(ptr) msvcrt._ctime64 @ stub _ctime64_s @ cdecl _cwait(ptr long long) msvcrt._cwait -@ stub _cwprintf +@ varargs _cwprintf(wstr) msvcrt._cwprintf @ stub _cwprintf_l @ stub _cwprintf_p @ stub _cwprintf_p_l @@ -1056,13 +1056,13 @@ @ cdecl _unlock_file(ptr) msvcrt._unlock_file @ cdecl _utime32(str ptr) msvcrt._utime32 @ cdecl _utime64(str ptr) msvcrt._utime64 -@ stub _vcprintf +@ cdecl _vcprintf(str ptr) msvcrt._vcprintf @ stub _vcprintf_l @ stub _vcprintf_p @ stub _vcprintf_p_l @ stub _vcprintf_s @ stub _vcprintf_s_l -@ stub _vcwprintf +@ cdecl _vcwprintf(wstr ptr) msvcrt._vcwprintf @ stub _vcwprintf_l @ stub _vcwprintf_p @ stub _vcwprintf_p_l diff --git a/dlls/msvcrt/console.c b/dlls/msvcrt/console.c index 0411eb8..e23ff3e 100644 --- a/dlls/msvcrt/console.c +++ b/dlls/msvcrt/console.c @@ -22,6 +22,7 @@ */
#include "msvcrt.h" +#include "winnls.h" #include "wincon.h" #include "mtdll.h" #include "wine/debug.h" @@ -299,35 +300,89 @@ int CDECL _kbhit(void)
/********************************************************************* + * _vcprintf (MSVCRT.@) + */ +int CDECL _vcprintf(const char* format, __ms_va_list valist) +{ + char buf[2048]; + LPWSTR formatW = NULL; + DWORD sz; + pf_output out; + int retval; + + out.unicode = FALSE; + out.buf.A = out.grow.A = buf; + out.used = 0; + out.len = sizeof(buf); + + sz = MultiByteToWideChar( CP_ACP, 0, format, -1, NULL, 0 ); + formatW = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, format, -1, formatW, sz ); + + if ((retval = pf_vsnprintf( &out, formatW, NULL, FALSE, valist )) > 0) + { + LOCK_CONSOLE; + retval = _cputs( out.buf.A ); + UNLOCK_CONSOLE; + } + HeapFree( GetProcessHeap(), 0, formatW ); + if (out.buf.A != buf) + MSVCRT_free (out.buf.A); + return retval; +} + +/********************************************************************* * _cprintf (MSVCRT.@) */ int CDECL _cprintf(const char* format, ...) { - char buf[2048], *mem = buf; - int written, resize = sizeof(buf), retval; + int retval; __ms_va_list valist;
__ms_va_start( valist, format ); - /* There are two conventions for snprintf failing: - * Return -1 if we truncated, or - * Return the number of bytes that would have been written - * The code below handles both cases - */ - while ((written = MSVCRT_vsnprintf( mem, resize, format, valist )) == -1 || - written > resize) + retval = _vcprintf(format, valist); + __ms_va_end(valist); + + return retval; +} + + +/********************************************************************* + * _vcwprintf (MSVCRT.@) + */ +int CDECL _vcwprintf(const MSVCRT_wchar_t* format, __ms_va_list valist) +{ + MSVCRT_wchar_t buf[2048]; + pf_output out; + int retval; + + out.unicode = TRUE; + out.buf.W = out.grow.W = buf; + out.used = 0; + out.len = sizeof(buf) / sizeof(buf[0]); + + if ((retval = pf_vsnprintf( &out, format, NULL, FALSE, valist )) >= 0) { - resize = (written == -1 ? resize * 2 : written + 1); - if (mem != buf) - MSVCRT_free (mem); - if (!(mem = MSVCRT_malloc(resize))) - return MSVCRT_EOF; - __ms_va_start( valist, format ); + LOCK_CONSOLE; + retval = _cputws( out.buf.W ); + UNLOCK_CONSOLE; } + if (out.buf.W != buf) + MSVCRT_free (out.buf.W); + return retval; +} + +/********************************************************************* + * _cwprintf (MSVCRT.@) + */ +int CDECL _cwprintf(const MSVCRT_wchar_t* format, ...) +{ + int retval; + __ms_va_list valist; + + __ms_va_start( valist, format ); + retval = _vcwprintf(format, valist); __ms_va_end(valist); - LOCK_CONSOLE; - retval = _cputs( mem ); - UNLOCK_CONSOLE; - if (mem != buf) - MSVCRT_free (mem); + return retval; } diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec index 42c2469..4a531f4 100644 --- a/dlls/msvcrt/msvcrt.spec +++ b/dlls/msvcrt/msvcrt.spec @@ -361,7 +361,7 @@ # stub _ctime64_s @ extern _ctype MSVCRT__ctype @ cdecl _cwait(ptr long long) -# stub _cwprintf +@ varargs _cwprintf(wstr) # stub _cwprintf_l # stub _cwprintf_p # stub _cwprintf_p_l @@ -992,13 +992,13 @@ @ cdecl _unlock_file(ptr) MSVCRT__unlock_file @ cdecl _utime32(str ptr) @ cdecl _utime64(str ptr) -# stub _vcprintf +@ cdecl _vcprintf(str ptr) # stub _vcprintf_l # stub _vcprintf_p # stub _vcprintf_p_l # stub _vcprintf_s # stub _vcprintf_s_l -# stub _vcwprintf +@ cdecl _vcwprintf(wstr ptr) # stub _vcwprintf_l # stub _vcwprintf_p # stub _vcwprintf_p_l