1 #include "../git-compat-util.h"
4 * The size parameter specifies the available space, i.e. includes
5 * the trailing NUL byte; but Windows's vsnprintf uses the entire
6 * buffer and avoids the trailing NUL, should the buffer be exactly
7 * big enough for the result. Defining SNPRINTF_SIZE_CORR to 1 will
8 * therefore remove 1 byte from the reported buffer size, so we
9 * always have room for a trailing NUL byte.
11 #ifndef SNPRINTF_SIZE_CORR
12 #if defined(WIN32) && (!defined(__GNUC__) || __GNUC__ < 4)
13 #define SNPRINTF_SIZE_CORR 1
15 #define SNPRINTF_SIZE_CORR 0
20 int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap)
26 ret = vsnprintf(str, maxsize-SNPRINTF_SIZE_CORR, format, ap);
29 /* Windows does not NUL-terminate if result fills buffer */
41 str = realloc(s, maxsize);
45 ret = vsnprintf(str, maxsize-SNPRINTF_SIZE_CORR, format, ap);
53 int git_snprintf(char *str, size_t maxsize, const char *format, ...)
59 ret = git_vsnprintf(str, maxsize, format, ap);