Piotr Caban : msvcrt: Use callback based printf in fprintf functions family .
Alexandre Julliard
julliard at winehq.org
Mon Apr 25 12:47:14 CDT 2011
Module: wine
Branch: master
Commit: b9e456aa7976f6dde080fe8eae3435e4dcb4886b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=b9e456aa7976f6dde080fe8eae3435e4dcb4886b
Author: Piotr Caban <piotr at codeweavers.com>
Date: Wed Apr 20 14:42:36 2011 +0200
msvcrt: Use callback based printf in fprintf functions family.
---
dlls/msvcrt/file.c | 118 ++++++++++------------------------------------------
1 files changed, 22 insertions(+), 96 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index e34c11f..30613ca 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -3379,37 +3379,22 @@ MSVCRT_FILE* CDECL MSVCRT_tmpfile(void)
return file;
}
+static int puts_clbk_file_a(void *file, int len, const char *str)
+{
+ return MSVCRT_fwrite(str, sizeof(char), len, file);
+}
+
+static int puts_clbk_file_w(void *file, int len, const MSVCRT_wchar_t *str)
+{
+ return MSVCRT_fwrite(str, sizeof(MSVCRT_wchar_t), len, file);
+}
+
/*********************************************************************
* vfprintf (MSVCRT.@)
*/
int CDECL MSVCRT_vfprintf(MSVCRT_FILE* file, const char *format, __ms_va_list valist)
{
- char buf[2048];
- LPWSTR formatW = NULL;
- DWORD sz;
- pf_output out;
- int written, 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 ((written = pf_vsnprintf( &out, formatW, NULL, FALSE, valist )) >= 0)
- {
- retval = MSVCRT_fwrite(out.buf.A, sizeof(*out.buf.A), written, file);
- }
- else retval = -1;
-
- HeapFree( GetProcessHeap(), 0, formatW );
-
- if (out.buf.A != out.grow.A)
- MSVCRT_free (out.buf.A);
- return retval;
+ return pf_printf_a(puts_clbk_file_a, file, format, NULL, FALSE, FALSE, arg_clbk_valist, NULL, valist);
}
/*********************************************************************
@@ -3417,38 +3402,12 @@ int CDECL MSVCRT_vfprintf(MSVCRT_FILE* file, const char *format, __ms_va_list va
*/
int CDECL MSVCRT_vfprintf_s(MSVCRT_FILE* file, const char *format, __ms_va_list valist)
{
- char buf[2048];
- LPWSTR formatW = NULL;
- DWORD sz;
- pf_output out;
- int written, retval;
-
- if( !MSVCRT_CHECK_PMT( file != NULL ) )
- {
- *MSVCRT__errno() = MSVCRT_EINVAL;
- return -1;
- }
-
- 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 ((written = pf_vsnprintf( &out, formatW, NULL, TRUE, valist )) >= 0)
- {
- retval = MSVCRT_fwrite(out.buf.A, sizeof(*out.buf.A), written, file);
- }
- else retval = -1;
-
- HeapFree( GetProcessHeap(), 0, formatW );
+ if(!MSVCRT_CHECK_PMT(file != NULL)) {
+ *MSVCRT__errno() = MSVCRT_EINVAL;
+ return -1;
+ }
- if (out.buf.A != out.grow.A)
- MSVCRT_free (out.buf.A);
- return retval;
+ return pf_printf_a(puts_clbk_file_a, file, format, NULL, FALSE, TRUE, arg_clbk_valist, NULL, valist);
}
/*********************************************************************
@@ -3456,23 +3415,7 @@ int CDECL MSVCRT_vfprintf_s(MSVCRT_FILE* file, const char *format, __ms_va_list
*/
int CDECL MSVCRT_vfwprintf(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, __ms_va_list valist)
{
- MSVCRT_wchar_t buf[2048];
- pf_output out;
- int written, retval;
-
- out.unicode = TRUE;
- out.buf.W = out.grow.W = buf;
- out.used = 0;
- out.len = sizeof(buf) / sizeof(buf[0]);
-
- if ((written = pf_vsnprintf( &out, format, NULL, FALSE, valist )) >= 0)
- {
- retval = MSVCRT_fwrite(out.buf.W, sizeof(*out.buf.W), written, file);
- }
- else retval = -1;
- if (out.buf.W != out.grow.W)
- MSVCRT_free (out.buf.W);
- return retval;
+ return pf_printf_w(puts_clbk_file_w, file, format, NULL, FALSE, FALSE, arg_clbk_valist, NULL, valist);
}
/*********************************************************************
@@ -3480,29 +3423,12 @@ int CDECL MSVCRT_vfwprintf(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, __ms
*/
int CDECL MSVCRT_vfwprintf_s(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, __ms_va_list valist)
{
- MSVCRT_wchar_t buf[2048];
- pf_output out;
- int written, retval;
-
- if( !MSVCRT_CHECK_PMT( file != NULL ) )
- {
- *MSVCRT__errno() = MSVCRT_EINVAL;
- return -1;
- }
-
- out.unicode = TRUE;
- out.buf.W = out.grow.W = buf;
- out.used = 0;
- out.len = sizeof(buf) / sizeof(buf[0]);
+ if(!MSVCRT_CHECK_PMT( file != NULL)) {
+ *MSVCRT__errno() = MSVCRT_EINVAL;
+ return -1;
+ }
- if ((written = pf_vsnprintf( &out, format, NULL, TRUE, valist )) >= 0)
- {
- retval = MSVCRT_fwrite(out.buf.W, sizeof(*out.buf.W), written, file);
- }
- else retval = -1;
- if (out.buf.W != out.grow.W)
- MSVCRT_free (out.buf.W);
- return retval;
+ return pf_printf_w(puts_clbk_file_w, file, format, NULL, FALSE, TRUE, arg_clbk_valist, NULL, valist);
}
/*********************************************************************
More information about the wine-cvs
mailing list