ucrtbase: Add defines for the printf/scanf options constants.
Avoid using hardcoded magic numbers for these options. Signed-off-by: Martin Storsjo <martin@martin.st> Signed-off-by: Piotr Caban <piotr@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
4b47da3ad7
commit
fcf9ec8080
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue