[PATCH] ucrtbase: Implement some printf functions

Martin Storsjö martin at martin.st
Tue Oct 20 03:50:36 CDT 2015


On Thu, 15 Oct 2015, Martin Storsjo wrote:

> 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.
>
> Some rudimentary tests are added (based on the msvcrt printf tests),
> testing to make sure the snprintf truncation/return values are
> handled correctly.
>
> These new functions also should support the C99 conversion
> specifiers; this is not yet implemented.
>
> Signed-off-by: Martin Storsjo <martin at martin.st>
> ---
> .../api-ms-win-crt-stdio-l1-1-0.spec               |  10 +-
> dlls/msvcrt/file.c                                 |  28 +++
> dlls/msvcrt/printf.h                               |  20 ++
> dlls/msvcrt/wcs.c                                  |  34 +++
> dlls/ucrtbase/tests/Makefile.in                    |   1 +
> dlls/ucrtbase/tests/printf.c                       | 259 +++++++++++++++++++++
> dlls/ucrtbase/ucrtbase.spec                        |  10 +-
> 7 files changed, 352 insertions(+), 10 deletions(-)
> create mode 100644 dlls/ucrtbase/tests/printf.c
>
> diff --git a/dlls/msvcrt/printf.h b/dlls/msvcrt/printf.h
> index 4757931..bd2dbf3 100644
> --- a/dlls/msvcrt/printf.h
> +++ b/dlls/msvcrt/printf.h
> @@ -64,6 +64,26 @@ static int FUNC_NAME(puts_clbk_str)(void *ctx, int len, const APICHAR *str)
>     return len;
> }
>
> +static int FUNC_NAME(puts_clbk_str_c99)(void *ctx, int len, const APICHAR *str)
> +{
> +    struct FUNC_NAME(_str_ctx) *out = ctx;
> +
> +    if(!out->buf)
> +        return len;
> +
> +    if(out->len - 1 < len) {
> +        memcpy(out->buf, str, (out->len - 1)*sizeof(APICHAR));
> +        out->buf += out->len - 1;
> +        out->len = 1;
> +        return len;
> +    }
> +
> +    memcpy(out->buf, str, len*sizeof(APICHAR));
> +    out->buf += len;
> +    out->len -= len;
> +    return len;
> +}
> +

FWIW, this gives warnings about puts_clbk_str_c99_w being defined but 
unused. It will be necessary later in case someone wants to implement the 
wchar versions of the printf functions for ucrtbase, but what should be 
done in the meantime? Just define this function somewhere else in wcs.c 
instead?

// Martin



More information about the wine-devel mailing list