[v2] msvcrt: Introduce vf[w]printf_helper function.

Gijs Vermeulen gijsvrm at gmail.com
Mon Oct 2 14:46:37 CDT 2017


Signed-off-by: Gijs Vermeulen <gijsvrm at gmail.com>
---
 dlls/msvcrt/file.c | 160 +++++++++++------------------------------------------
 1 file changed, 33 insertions(+), 127 deletions(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 2b43a20345..c87ff02d63 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -5048,41 +5048,45 @@ static int puts_clbk_file_w(void *file, int len, const MSVCRT_wchar_t *str)
     return len;
 }
 
-/*********************************************************************
- *		vfprintf (MSVCRT.@)
- */
-int CDECL MSVCRT_vfprintf(MSVCRT_FILE* file, const char *format, __ms_va_list valist)
+static int vfprintf_vfwprintf_helper(MSVCRT_FILE* file, const char *format, const MSVCRT_wchar_t *format_wide,
+        __ms_va_list valist, MSVCRT__locale_t locale, DWORD options, BOOL wide)
 {
     BOOL tmp_buf;
     int ret;
 
+    if(!MSVCRT_CHECK_PMT( file != NULL )) return -1;
+    if(!(wide && MSVCRT_CHECK_PMT( format != NULL ))) return -1;
+    if(wide && !MSVCRT_CHECK_PMT( format_wide != NULL )) return -1;
+
     MSVCRT__lock_file(file);
     tmp_buf = add_std_buffer(file);
-    ret = pf_printf_a(puts_clbk_file_a, file, format, NULL, 0, arg_clbk_valist, NULL, &valist);
+
+    if(!wide)
+        ret = pf_printf_a(puts_clbk_file_a, file, format, locale, options, arg_clbk_valist, NULL, &valist);
+    else
+        ret = pf_printf_w(puts_clbk_file_w, file, format_wide, locale, options, arg_clbk_valist, NULL, &valist);
+
     if(tmp_buf) remove_std_buffer(file);
     MSVCRT__unlock_file(file);
 
     return ret;
 }
 
+/*********************************************************************
+ *		vfprintf (MSVCRT.@)
+ */
+int CDECL MSVCRT_vfprintf(MSVCRT_FILE* file, const char *format, __ms_va_list valist)
+{
+    return vfprintf_vfwprintf_helper(file, format, NULL, valist, NULL, 0, FALSE);
+}
+
 /*********************************************************************
  *		vfprintf_s (MSVCRT.@)
  */
 int CDECL MSVCRT_vfprintf_s(MSVCRT_FILE* file, const char *format, __ms_va_list valist)
 {
-    BOOL tmp_buf;
-    int ret;
-
-    if(!MSVCRT_CHECK_PMT(file != NULL)) return -1;
-
-    MSVCRT__lock_file(file);
-    tmp_buf = add_std_buffer(file);
-    ret = pf_printf_a(puts_clbk_file_a, file, format, NULL,
-            MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER, arg_clbk_valist, NULL, &valist);
-    if(tmp_buf) remove_std_buffer(file);
-    MSVCRT__unlock_file(file);
-
-    return ret;
+    return vfprintf_vfwprintf_helper(file, format, NULL, valist, NULL,
+            MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER, FALSE);
 }
 
 /*********************************************************************
@@ -5090,16 +5094,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)
 {
-    BOOL tmp_buf;
-    int ret;
-
-    MSVCRT__lock_file(file);
-    tmp_buf = add_std_buffer(file);
-    ret = pf_printf_w(puts_clbk_file_w, file, format, NULL, 0, arg_clbk_valist, NULL, &valist);
-    if(tmp_buf) remove_std_buffer(file);
-    MSVCRT__unlock_file(file);
-
-    return ret;
+    return vfprintf_vfwprintf_helper(file, NULL, format, valist, NULL, 0, TRUE);
 }
 
 /*********************************************************************
@@ -5107,19 +5102,8 @@ 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)
 {
-    BOOL tmp_buf;
-    int ret;
-
-    if (!MSVCRT_CHECK_PMT( file != NULL )) return -1;
-
-    MSVCRT__lock_file(file);
-    tmp_buf = add_std_buffer(file);
-    ret = pf_printf_w(puts_clbk_file_w, file, format, NULL,
-            MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER, arg_clbk_valist, NULL, &valist);
-    if(tmp_buf) remove_std_buffer(file);
-    MSVCRT__unlock_file(file);
-
-    return ret;
+    return vfprintf_vfwprintf_helper(file, NULL, format, valist, NULL,
+            MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER, TRUE);
 }
 
 /*********************************************************************
@@ -5128,22 +5112,10 @@ int CDECL MSVCRT_vfwprintf_s(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, __
 int CDECL MSVCRT__stdio_common_vfprintf(unsigned __int64 options, MSVCRT_FILE *file, const char *format,
                                         MSVCRT__locale_t locale, __ms_va_list valist)
 {
-    BOOL tmp_buf;
-    int ret;
-
-    if (!MSVCRT_CHECK_PMT( file != NULL )) return -1;
-
-    MSVCRT__lock_file(file);
-    tmp_buf = add_std_buffer(file);
-
     if (options & ~UCRTBASE_PRINTF_MASK)
         FIXME("options %s not handled\n", wine_dbgstr_longlong(options));
-    ret = pf_printf_a(puts_clbk_file_a, file, format, locale,
-            options & UCRTBASE_PRINTF_MASK, arg_clbk_valist, NULL, &valist);
-    if(tmp_buf) remove_std_buffer(file);
-    MSVCRT__unlock_file(file);
 
-    return ret;
+    return vfprintf_vfwprintf_helper(file, format, NULL, valist, locale, options & UCRTBASE_PRINTF_MASK, FALSE);
 }
 
 /*********************************************************************
@@ -5152,25 +5124,11 @@ int CDECL MSVCRT__stdio_common_vfprintf(unsigned __int64 options, MSVCRT_FILE *f
 int CDECL MSVCRT__stdio_common_vfprintf_s(unsigned __int64 options, MSVCRT_FILE *file, const char *format,
                                           MSVCRT__locale_t locale, __ms_va_list valist)
 {
-    BOOL tmp_buf;
-    int ret;
-
-    if (!MSVCRT_CHECK_PMT(file != NULL)) return -1;
-
-    MSVCRT__lock_file(file);
-    tmp_buf = add_std_buffer(file);
-
     if (options & ~UCRTBASE_PRINTF_MASK)
         FIXME("options %s not handled\n", wine_dbgstr_longlong(options));
 
-    ret = pf_printf_a(puts_clbk_file_a, file, format, locale,
-            (options & UCRTBASE_PRINTF_MASK) | MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER,
-            arg_clbk_valist, NULL, &valist);
-
-    if (tmp_buf) remove_std_buffer(file);
-    MSVCRT__unlock_file(file);
-
-    return ret;
+    return vfprintf_vfwprintf_helper(file, format, NULL, valist, locale,
+            (options & UCRTBASE_PRINTF_MASK) | MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER, FALSE);
 }
 
 /*********************************************************************
@@ -5179,25 +5137,10 @@ int CDECL MSVCRT__stdio_common_vfprintf_s(unsigned __int64 options, MSVCRT_FILE
 int CDECL MSVCRT__stdio_common_vfwprintf(unsigned __int64 options, MSVCRT_FILE *file, const MSVCRT_wchar_t *format,
                                          MSVCRT__locale_t locale, __ms_va_list valist)
 {
-    BOOL tmp_buf;
-    int ret;
-
-    if (!MSVCRT_CHECK_PMT( file != NULL )) return -1;
-    if (!MSVCRT_CHECK_PMT( format != NULL )) return -1;
-
-    MSVCRT__lock_file(file);
-    tmp_buf = add_std_buffer(file);
-
     if (options & ~UCRTBASE_PRINTF_MASK)
         FIXME("options %s not handled\n", wine_dbgstr_longlong(options));
 
-    ret = pf_printf_w(puts_clbk_file_w, file, format, locale,
-            options & UCRTBASE_PRINTF_MASK, arg_clbk_valist, NULL, &valist);
-
-    if(tmp_buf) remove_std_buffer(file);
-    MSVCRT__unlock_file(file);
-
-    return ret;
+    return vfprintf_vfwprintf_helper(file, NULL, format, valist, locale, options & UCRTBASE_PRINTF_MASK, TRUE);
 }
 
 /*********************************************************************
@@ -5206,26 +5149,11 @@ int CDECL MSVCRT__stdio_common_vfwprintf(unsigned __int64 options, MSVCRT_FILE *
 int CDECL MSVCRT__stdio_common_vfwprintf_s(unsigned __int64 options, MSVCRT_FILE *file, const MSVCRT_wchar_t *format,
                                            MSVCRT__locale_t locale, __ms_va_list valist)
 {
-    BOOL tmp_buf;
-    int ret;
-
-    if (!MSVCRT_CHECK_PMT(file != NULL)) return -1;
-    if (!MSVCRT_CHECK_PMT(format != NULL)) return -1;
-
-    MSVCRT__lock_file(file);
-    tmp_buf = add_std_buffer(file);
-
     if (options & ~UCRTBASE_PRINTF_MASK)
         FIXME("options %s not handled\n", wine_dbgstr_longlong(options));
 
-    ret = pf_printf_w(puts_clbk_file_w, file, format, locale,
-            (options & UCRTBASE_PRINTF_MASK) | MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER,
-            arg_clbk_valist, NULL, &valist);
-
-    if (tmp_buf) remove_std_buffer(file);
-    MSVCRT__unlock_file(file);
-
-    return ret;
+    return vfprintf_vfwprintf_helper(file, NULL, format, valist, locale,
+            (options & UCRTBASE_PRINTF_MASK) | MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER, TRUE);
 }
 
 /*********************************************************************
@@ -5234,18 +5162,7 @@ int CDECL MSVCRT__stdio_common_vfwprintf_s(unsigned __int64 options, MSVCRT_FILE
 int CDECL MSVCRT__vfprintf_l(MSVCRT_FILE* file, const char *format,
         MSVCRT__locale_t locale, __ms_va_list valist)
 {
-    BOOL tmp_buf;
-    int ret;
-
-    if(!MSVCRT_CHECK_PMT(file != NULL)) return -1;
-
-    MSVCRT__lock_file(file);
-    tmp_buf = add_std_buffer(file);
-    ret = pf_printf_a(puts_clbk_file_a, file, format, locale, 0, arg_clbk_valist, NULL, &valist);
-    if(tmp_buf) remove_std_buffer(file);
-    MSVCRT__unlock_file(file);
-
-    return ret;
+    return vfprintf_vfwprintf_helper(file, format, NULL, valist, locale, 0, FALSE);
 }
 
 /*********************************************************************
@@ -5254,18 +5171,7 @@ int CDECL MSVCRT__vfprintf_l(MSVCRT_FILE* file, const char *format,
 int CDECL MSVCRT__vfwprintf_l(MSVCRT_FILE* file, const MSVCRT_wchar_t *format,
         MSVCRT__locale_t locale, __ms_va_list valist)
 {
-    BOOL tmp_buf;
-    int ret;
-
-    if (!MSVCRT_CHECK_PMT( file != NULL )) return -1;
-
-    MSVCRT__lock_file(file);
-    tmp_buf = add_std_buffer(file);
-    ret = pf_printf_w(puts_clbk_file_w, file, format, locale, 0, arg_clbk_valist, NULL, &valist);
-    if(tmp_buf) remove_std_buffer(file);
-    MSVCRT__unlock_file(file);
-
-    return ret;
+    return vfprintf_vfwprintf_helper(file, NULL, format, valist, locale, 0, TRUE);
 }
 
 /*********************************************************************
-- 
2.14.2.windows.1




More information about the wine-patches mailing list