Commit 255a7fe0 authored by Martin Storsjo's avatar Martin Storsjo Committed by Alexandre Julliard

ucrtbase: Implement some printf functions.

Not all functions are implemented (yet not all variants are implemented in the normal msvcrt either). The new functions are more generalized and are C99 compliant. They take an options parameter that e.g. for the snprintf family of functions indicate whether the truncation and return value should be handled as before or in the standards compliant way. Signed-off-by: 's avatarMartin Storsjo <martin@martin.st> Signed-off-by: 's avatarPiotr Caban <piotr@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent a1515c68
@ stub __acrt_iob_func
@ cdecl __acrt_iob_func(long) ucrtbase.__acrt_iob_func
@ cdecl __p__commode() ucrtbase.__p__commode
@ cdecl __p__fmode() ucrtbase.__p__fmode
@ stub __stdio_common_vfprintf
@ cdecl __stdio_common_vfprintf(int64 ptr ptr ptr ptr) ucrtbase.__stdio_common_vfprintf
@ stub __stdio_common_vfprintf_p
@ stub __stdio_common_vfprintf_s
@ stub __stdio_common_vfscanf
......@@ -9,13 +9,13 @@
@ stub __stdio_common_vfwprintf_p
@ stub __stdio_common_vfwprintf_s
@ stub __stdio_common_vfwscanf
@ stub __stdio_common_vsnprintf_s
@ cdecl __stdio_common_vsnprintf_s(int64 ptr long long ptr ptr ptr) ucrtbase.__stdio_common_vsnprintf_s
@ stub __stdio_common_vsnwprintf_s
@ stub __stdio_common_vsprintf
@ cdecl __stdio_common_vsprintf(int64 ptr long ptr ptr ptr) ucrtbase.__stdio_common_vsprintf
@ stub __stdio_common_vsprintf_p
@ stub __stdio_common_vsprintf_s
@ cdecl __stdio_common_vsprintf_s(int64 ptr long ptr ptr ptr) ucrtbase.__stdio_common_vsprintf_s
@ stub __stdio_common_vsscanf
@ stub __stdio_common_vswprintf
@ cdecl __stdio_common_vswprintf(int64 ptr long ptr ptr ptr) ucrtbase.__stdio_common_vswprintf
@ stub __stdio_common_vswprintf_p
@ stub __stdio_common_vswprintf_s
@ stub __stdio_common_vswscanf
......
......@@ -758,6 +758,14 @@ MSVCRT_FILE * CDECL MSVCRT___iob_func(void)
}
/*********************************************************************
* __acrt_iob_func(MSVCRT.@)
*/
MSVCRT_FILE * CDECL MSVCRT___acrt_iob_func(unsigned idx)
{
return &MSVCRT__iob[idx];
}
/*********************************************************************
* _access (MSVCRT.@)
*/
int CDECL MSVCRT__access(const char *filename, int mode)
......@@ -4976,6 +4984,26 @@ int CDECL MSVCRT_vfwprintf_s(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, __
}
/*********************************************************************
* __stdio_common_vfprintf (MSVCRT.@)
*/
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);
ret = pf_printf_a(puts_clbk_file_a, file, format, locale, FALSE, FALSE, arg_clbk_valist, NULL, &valist);
if(tmp_buf) remove_std_buffer(file);
MSVCRT__unlock_file(file);
return ret;
}
/*********************************************************************
* _vfwprintf_l (MSVCRT.@)
*/
int CDECL MSVCRT__vfwprintf_l(MSVCRT_FILE* file, const MSVCRT_wchar_t *format,
......
......@@ -694,6 +694,44 @@ int CDECL MSVCRT_vsnprintf( char *str, MSVCRT_size_t len,
return ret;
}
static int puts_clbk_str_c99_a(void *ctx, int len, const char *str)
{
struct _str_ctx_a *out = ctx;
if(!out->buf)
return len;
if(out->len - 1 < len) {
memcpy(out->buf, str, out->len - 1);
out->buf += out->len - 1;
out->len = 1;
return len;
}
memcpy(out->buf, str, len);
out->buf += len;
out->len -= len;
return len;
}
/*********************************************************************
* __stdio_common_vsprintf (MSVCRT.@)
*/
int CDECL MSVCRT__stdio_common_vsprintf( unsigned __int64 options, char *str, MSVCRT_size_t len, const char *format,
MSVCRT__locale_t locale, __ms_va_list valist )
{
static const char nullbyte = '\0';
struct _str_ctx_a ctx = {len, str};
int ret;
if (options != 1 && options != 2)
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,
&ctx, format, locale, FALSE, FALSE, arg_clbk_valist, NULL, &valist);
puts_clbk_str_a(&ctx, 1, &nullbyte);
return ret;
}
/*********************************************************************
* _vsnprintf_l (MSVCRT.@)
*/
......@@ -801,6 +839,24 @@ int CDECL MSVCRT_vsnprintf_s( char *str, MSVCRT_size_t sizeOfBuffer,
}
/*********************************************************************
* __stdio_common_vsnprintf_s (MSVCRT.@)
*/
int CDECL MSVCRT__stdio_common_vsnprintf_s( unsigned __int64 options, char *str, MSVCRT_size_t sizeOfBuffer, MSVCRT_size_t count, const char *format,
MSVCRT__locale_t locale, __ms_va_list valist )
{
return MSVCRT_vsnprintf_s_l(str, sizeOfBuffer, count, format, locale, valist);
}
/*********************************************************************
* __stdio_common_vsprintf_s (MSVCRT.@)
*/
int CDECL MSVCRT__stdio_common_vsprintf_s( unsigned __int64 options, char *str, MSVCRT_size_t count, const char *format,
MSVCRT__locale_t locale, __ms_va_list valist )
{
return MSVCRT_vsnprintf_s_l(str, INT_MAX, count, format, locale, valist);
}
/*********************************************************************
* vsprintf (MSVCRT.@)
*/
int CDECL MSVCRT_vsprintf( char *str, const char *format, __ms_va_list valist)
......@@ -1084,6 +1140,44 @@ int CDECL MSVCRT__snwprintf_s_l( MSVCRT_wchar_t *str, unsigned int len, unsigned
return retval;
}
static int puts_clbk_str_c99_w(void *ctx, int len, const MSVCRT_wchar_t *str)
{
struct _str_ctx_w *out = ctx;
if(!out->buf)
return len;
if(out->len - 1 < len) {
memcpy(out->buf, str, (out->len - 1)*sizeof(MSVCRT_wchar_t));
out->buf += out->len - 1;
out->len = 1;
return len;
}
memcpy(out->buf, str, len*sizeof(MSVCRT_wchar_t));
out->buf += len;
out->len -= len;
return len;
}
/*********************************************************************
* __stdio_common_vsprintf (MSVCRT.@)
*/
int CDECL MSVCRT__stdio_common_vswprintf( unsigned __int64 options, MSVCRT_wchar_t *str, MSVCRT_size_t len, const MSVCRT_wchar_t *format,
MSVCRT__locale_t locale, __ms_va_list valist )
{
static const MSVCRT_wchar_t nullbyte = '\0';
struct _str_ctx_w ctx = {len, str};
int ret;
if (options != 1 && options != 2)
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,
&ctx, format, locale, FALSE, FALSE, arg_clbk_valist, NULL, &valist);
puts_clbk_str_w(&ctx, 1, &nullbyte);
return ret;
}
/*********************************************************************
* sprintf (MSVCRT.@)
*/
......
......@@ -2,4 +2,5 @@ TESTDLL = ucrtbase.dll
APPMODE = -mno-cygwin
C_SRCS = \
printf.c \
string.c
......@@ -72,7 +72,7 @@
@ cdecl ___lc_locale_name_func()
@ cdecl ___mb_cur_max_func() MSVCRT____mb_cur_max_func
@ cdecl ___mb_cur_max_l_func(ptr)
@ stub __acrt_iob_func
@ cdecl __acrt_iob_func(long) MSVCRT___acrt_iob_func
@ stub __conio_common_vcprintf
@ stub __conio_common_vcprintf_p
@ stub __conio_common_vcprintf_s
......@@ -146,7 +146,7 @@
@ stub __std_type_info_destroy_list
@ stub __std_type_info_hash
@ stub __std_type_info_name
@ stub __stdio_common_vfprintf
@ cdecl __stdio_common_vfprintf(int64 ptr ptr ptr ptr) MSVCRT__stdio_common_vfprintf
@ stub __stdio_common_vfprintf_p
@ stub __stdio_common_vfprintf_s
@ stub __stdio_common_vfscanf
......@@ -154,13 +154,13 @@
@ stub __stdio_common_vfwprintf_p
@ stub __stdio_common_vfwprintf_s
@ stub __stdio_common_vfwscanf
@ stub __stdio_common_vsnprintf_s
@ cdecl __stdio_common_vsnprintf_s(int64 ptr long long ptr ptr ptr) MSVCRT__stdio_common_vsnprintf_s
@ stub __stdio_common_vsnwprintf_s
@ stub __stdio_common_vsprintf
@ cdecl __stdio_common_vsprintf(int64 ptr long ptr ptr ptr) MSVCRT__stdio_common_vsprintf
@ stub __stdio_common_vsprintf_p
@ stub __stdio_common_vsprintf_s
@ cdecl __stdio_common_vsprintf_s(int64 ptr long ptr ptr ptr) MSVCRT__stdio_common_vsprintf_s
@ stub __stdio_common_vsscanf
@ stub __stdio_common_vswprintf
@ cdecl __stdio_common_vswprintf(int64 ptr long ptr ptr ptr) MSVCRT__stdio_common_vswprintf
@ stub __stdio_common_vswprintf_p
@ stub __stdio_common_vswprintf_s
@ stub __stdio_common_vswscanf
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment