[PATCH 1/2] msvcrt: Introduce vfprintf helper function.

Gijs Vermeulen gijsvrm at gmail.com
Sun Sep 24 18:24:17 CDT 2017


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

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 8af9bc2db4..7f3048f534 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -5033,41 +5033,49 @@ 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_helper(MSVCRT_FILE* file, const char *format, __ms_va_list valist,
+        MSVCRT__locale_t locale, BOOL secure)
 {
     BOOL tmp_buf;
     int ret;
 
+    if(secure)
+        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, 0, arg_clbk_valist, NULL, &valist);
+
+    if(!secure)
+        ret = pf_printf_a(puts_clbk_file_a, file, format, NULL, 0, arg_clbk_valist, NULL, &valist);
+    else
+    {
+        if(!locale)
+            ret = pf_printf_a(puts_clbk_file_a, file, format, NULL,
+                    MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER, arg_clbk_valist, NULL, &valist);
+        else
+            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;
 }
 
+/*********************************************************************
+ *		vfprintf (MSVCRT.@)
+ */
+int CDECL MSVCRT_vfprintf(MSVCRT_FILE* file, const char *format, __ms_va_list valist)
+{
+    return vfprintf_helper(file, format, valist, NULL, 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_helper(file, format, valist, NULL, TRUE);
 }
 
 /*********************************************************************
@@ -5219,18 +5227,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_helper(file, format, valist, locale, TRUE);
 }
 
 /*********************************************************************
-- 
2.14.1.windows.1




More information about the wine-patches mailing list