<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59093>59093</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [LibC] Feature request: add snwprintf_s or snwprintf function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          nmoreaud
      </td>
    </tr>
</table>

<pre>
    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
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVMtu6zYQ_Rp5M5AhU35p4UXiNEVQJ4u-srygqJHEhiJ1-bDifn2HkpU6xb1FUcCyZT7OnDlzZkpTXQ5PwDvgcEzYPX2gwjMq06MFrit4gpafEUpEDRYraVF4rMAbaNHS-gVef1ytl0n2kGR3r61UCL2xXuoGnOkQnqWwxpnaf-ALU2G871uEk9ThHXrFfW1sl7DjHM8iV_LPGKjlHoYR148ROT1O91ZqXydsn7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