Skip to content

[LibC] Feature request: add snwprintf_s or snwprintf function #59093

@nmoreaud

Description

@nmoreaud

I am a C++ developer and I have been redirected to here by WG14.
While porting some Microsoft C++ code to the Linux platform, I have realized that while there are snprintf() and vsnprintf() functions for char*, there is no direct equivalent for wchar_t* in the C standard.

This function (snwprintf_s or snwprint / vsnwprintf) would greatly help us to write an efficient logger, compatible with printf syntax and wide strings. snwprintf_s is defined in Annex K of the C standard.

Do you think it could be added to LLVM C library?

Current alternative, swprintf(), doesn't accept NULL as an output argument, nor does it return the total expected size. We have to allocate a buffer of increasing size and hope that the formatting string and arguments are valid.
Emulation of snwprintf_s in our programs results in inefficient code.
I think snwprintf_s addition would be interesting to maintain the parity with existing char-based printf methods, and it would help us to make old code that targets Windows cross-platform.

Some background here:
https://en.cppreference.com/w/c/io/fwprintf#Notes
https://stackoverflow.com/questions/4107947/how-to-determine-buffer-size-for-vswprintf-under-linux-gcc
https://stackoverflow.com/questions/3693479/why-does-c-not-have-an-snwprintf-function
https://stackoverflow.com/a/46289793/3412316

Best Regards
Nicolas M

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImproving things as opposed to bug fixing, e.g. new or missing featurelibc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions