HomePhabricator

[libc++] Fix return value of snprintf_l() on Windows when buffer is too small

Authored by thomasanderson on Mar 26 2019, 12:51 PM.

Description

[libc++] Fix return value of snprintf_l() on Windows when buffer is too small

When the output buffer is too small to contain the output, vsnprintf()
fills the buffer and returns the number of characters that would have
been written if the buffer was sufficiently large.

_vnsprintf_s() on the other hand fills the buffer and returns -1 when this
happens. We want the former behavior, but we also want to be able to
pass in a locale to prevent having to call setlocale().

__stdio_common_vsprintf() is the only function general enough to get
the behavior we want.

Differential Revision: https://reviews.llvm.org/D59727

llvm-svn: 357024