Martin Storsjo : ucrtbase: Add defines for the printf/ scanf options constants.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Nov 2 09:47:15 CST 2015


Module: wine
Branch: master
Commit: fcf9ec80800d9b2bc6b874642a2f3f1d151009d0
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fcf9ec80800d9b2bc6b874642a2f3f1d151009d0

Author: Martin Storsjo <martin at martin.st>
Date:   Mon Nov  2 12:08:37 2015 +0200

ucrtbase: Add defines for the printf/scanf options constants.

Avoid using hardcoded magic numbers for these options.

Signed-off-by: Martin Storsjo <martin at martin.st>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcrt/msvcrt.h         | 10 ++++++++++
 dlls/msvcrt/scanf.c          |  2 +-
 dlls/msvcrt/wcs.c            | 10 ++++++----
 dlls/ucrtbase/tests/printf.c | 14 ++++++++++----
 4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index 8c07b94..a3b2595 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -1124,4 +1124,14 @@ extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,
 #define UNDNAME_NO_SPECIAL_SYMS          (0x4000)
 #define UNDNAME_NO_COMPLEX_TYPE          (0x8000)
 
+#define UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION (0x0001)
+#define UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR      (0x0002)
+#define UCRTBASE_PRINTF_LEGACY_WIDE_SPECIFIERS           (0x0004)
+#define UCRTBASE_PRINTF_LEGACY_MSVCRT_COMPATIBILITY      (0x0008)
+#define UCRTBASE_PRINTF_LEGACY_THREE_DIGIT_EXPONENTS     (0x0010)
+
+#define UCRTBASE_SCANF_SECURECRT                         (0x0001)
+#define UCRTBASE_SCANF_LEGACY_WIDE_SPECIFIERS            (0x0002)
+#define UCRTBASE_SCANF_LEGACY_MSVCRT_COMPATIBILITY       (0x0004)
+
 #endif /* __WINE_MSVCRT_H */
diff --git a/dlls/msvcrt/scanf.c b/dlls/msvcrt/scanf.c
index 9a0150f..b02977f 100644
--- a/dlls/msvcrt/scanf.c
+++ b/dlls/msvcrt/scanf.c
@@ -671,7 +671,7 @@ int CDECL MSVCRT__stdio_common_vsscanf(unsigned __int64 options,
                                        MSVCRT__locale_t locale,
                                        __ms_va_list valist)
 {
-    if (options != 2)
+    if (options != UCRTBASE_SCANF_LEGACY_WIDE_SPECIFIERS)
         FIXME("options %s not handled\n", wine_dbgstr_longlong(options));
     return MSVCRT_vsnscanf_l(input, length, format, locale, valist);
 }
diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c
index 321e4df..0bfddbb 100644
--- a/dlls/msvcrt/wcs.c
+++ b/dlls/msvcrt/wcs.c
@@ -724,9 +724,10 @@ int CDECL MSVCRT__stdio_common_vsprintf( unsigned __int64 options, char *str, MS
     struct _str_ctx_a ctx = {len, str};
     int ret;
 
-    if (options != 1 && options != 2)
+    if (options != UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION &&
+        options != UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR)
         FIXME("options %s not handled\n", wine_dbgstr_longlong(options));
-    ret = pf_printf_a(options & 2 ? puts_clbk_str_c99_a : puts_clbk_str_a,
+    ret = pf_printf_a(options & UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR ? puts_clbk_str_c99_a : puts_clbk_str_a,
             &ctx, format, locale, FALSE, FALSE, arg_clbk_valist, NULL, &valist);
     puts_clbk_str_a(&ctx, 1, &nullbyte);
     return ret;
@@ -1170,9 +1171,10 @@ int CDECL MSVCRT__stdio_common_vswprintf( unsigned __int64 options, MSVCRT_wchar
     struct _str_ctx_w ctx = {len, str};
     int ret;
 
-    if (options != 1 && options != 2)
+    if (options != UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION &&
+        options != UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR)
         FIXME("options %s not handled\n", wine_dbgstr_longlong(options));
-    ret = pf_printf_w(options & 2 ? puts_clbk_str_c99_w : puts_clbk_str_w,
+    ret = pf_printf_w(options & UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR ? puts_clbk_str_c99_w : puts_clbk_str_w,
             &ctx, format, locale, FALSE, FALSE, arg_clbk_valist, NULL, &valist);
     puts_clbk_str_w(&ctx, 1, &nullbyte);
     return ret;
diff --git a/dlls/ucrtbase/tests/printf.c b/dlls/ucrtbase/tests/printf.c
index 96f22c1..99d756e 100644
--- a/dlls/ucrtbase/tests/printf.c
+++ b/dlls/ucrtbase/tests/printf.c
@@ -30,6 +30,12 @@
 
 #include "wine/test.h"
 
+#define UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION (0x0001)
+#define UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR      (0x0002)
+#define UCRTBASE_PRINTF_LEGACY_WIDE_SPECIFIERS           (0x0004)
+#define UCRTBASE_PRINTF_LEGACY_MSVCRT_COMPATIBILITY      (0x0008)
+#define UCRTBASE_PRINTF_LEGACY_THREE_DIGIT_EXPONENTS     (0x0010)
+
 static int (__cdecl *p_vfprintf)(unsigned __int64 options, FILE *file, const char *format,
                                  void *locale, __ms_va_list valist);
 static int (__cdecl *p_vsprintf)(unsigned __int64 options, char *str, size_t len, const char *format,
@@ -91,7 +97,7 @@ static void test_snprintf (void)
     for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
         const char *fmt  = tests[i];
         const int expect = strlen(fmt) > bufsiz ? -1 : strlen(fmt);
-        const int n      = vsprintf_wrapper (1, buffer, bufsiz, fmt);
+        const int n      = vsprintf_wrapper (UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, buffer, bufsiz, fmt);
         const int valid  = n < 0 ? bufsiz : (n == bufsiz ? n : n+1);
 
         ok (n == expect, "\"%s\": expected %d, returned %d\n",
@@ -104,7 +110,7 @@ static void test_snprintf (void)
     for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
         const char *fmt  = tests[i];
         const int expect = strlen(fmt);
-        const int n      = vsprintf_wrapper (2, buffer, bufsiz, fmt);
+        const int n      = vsprintf_wrapper (UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, buffer, bufsiz, fmt);
         const int valid  = n >= bufsiz ? bufsiz - 1 : n < 0 ? 0 : n;
 
         ok (n == expect, "\"%s\": expected %d, returned %d\n",
@@ -144,7 +150,7 @@ static void test_swprintf (void)
     for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
         const wchar_t *fmt = tests[i];
         const int expect   = wcslen(fmt) > bufsiz ? -1 : wcslen(fmt);
-        const int n        = vswprintf_wrapper (1, buffer, bufsiz, fmt);
+        const int n        = vswprintf_wrapper (UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, buffer, bufsiz, fmt);
         const int valid    = n < 0 ? bufsiz : (n == bufsiz ? n : n+1);
 
         WideCharToMultiByte (CP_ACP, 0, buffer, -1, narrow, sizeof(narrow), NULL, NULL);
@@ -159,7 +165,7 @@ static void test_swprintf (void)
     for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
         const wchar_t *fmt = tests[i];
         const int expect   = wcslen(fmt);
-        const int n        = vswprintf_wrapper (2, buffer, bufsiz, fmt);
+        const int n        = vswprintf_wrapper (UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, buffer, bufsiz, fmt);
         const int valid    = n >= bufsiz ? bufsiz - 1 : n < 0 ? 0 : n;
 
         WideCharToMultiByte (CP_ACP, 0, buffer, -1, narrow, sizeof(narrow), NULL, NULL);




More information about the wine-cvs mailing list