| 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 <stdarg.h> |
| 8 | #include <stdio.h> |
| 9 | |
| 10 | int __cdecl __ms_vsnprintf (char *s,size_t n,const char *format,va_list arg) |
| 11 | { |
| 12 | int retval; |
| 13 | |
| 14 | /* _vsnprintf() does not work with zero length buffer |
| 15 | * so count number of character by _vscprintf() call */ |
| 16 | if (n == 0) |
| 17 | return _vscprintf(format, arg); |
| 18 | |
| 19 | retval = _vsnprintf(s, n, format, arg); |
| 20 | |
| 21 | /* _vsnprintf() does not fill trailing null byte if there is not place for it */ |
| 22 | if (retval < 0 || (size_t)retval == n) |
| 23 | s[n-1] = '\0'; |
| 24 | |
| 25 | /* _vsnprintf() returns negative number if buffer is too small |
| 26 | * so count number of character by _vscprintf() call */ |
| 27 | if (retval < 0) |
| 28 | retval = _vscprintf(format, arg); |
| 29 | |
| 30 | return retval; |
| 31 | } |