master
 1/**
 2 * This file has no copyright assigned and is placed in the Public Domain.
 3 * This file is part of the mingw-w64 runtime package.
 4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 5 */
 6#define __CRT__NO_INLINE
 7#include <_mingw.h>
 8#include <stdarg.h>
 9#include <wchar.h>
10
11int  __cdecl __ms_vsnwprintf(wchar_t *buffer,  size_t n, const wchar_t * format, va_list argptr);
12
13int  __cdecl __ms_vsnwprintf(wchar_t *buffer,  size_t n, const wchar_t * format, va_list argptr)
14{
15    int retval;
16
17    /* _vsnwprintf() does not work with zero length buffer
18     * so count number of characters by _vscwprintf() call */
19    if (n == 0)
20        return _vscwprintf(format, argptr);
21
22    retval = _vsnwprintf(buffer, n, format, argptr);
23
24    /* _vsnwprintf() does not fill trailing null character if there is not place for it */
25    if (retval < 0 || (size_t)retval == n)
26        buffer[n-1] = '\0';
27
28    /* _vsnwprintf() returns negative number if buffer is too small
29     * so count number of characters by _vscwprintf() call */
30    if (retval < 0)
31        retval = _vscwprintf(format, argptr);
32
33    return retval;
34}