20 #define _XOPEN_SOURCE 500
23 #include <basestring_vsnprintf.h>
26 basestring_snprintf(
char *str,
size_t size,
const char *format, ...)
31 ret= basestring_vsnprintf(str, size, format, ap);
36 #ifdef SNPRINTF_RETURN_TRUNC
38 vsnprintf_doubling(
size_t size,
const char *format, va_list ap)
43 while (ret < 0 || ret >= (
int)size)
45 buf = realloc(buf, size*=2);
46 ret = vsnprintf(buf, size, format, ap);
54 basestring_vsnprintf(
char *str,
size_t size,
const char *format, va_list ap)
61 return basestring_vsnprintf(buf, 1, format, ap);
63 ret = IF_WIN(_vsnprintf,vsnprintf)(str,
size, format, ap);
64 if (ret >= 0 && ret < (
int)
size)
67 if (ret < 0 && errno == EINVAL)
70 return _vscprintf(format, ap);
72 #ifdef SNPRINTF_RETURN_TRUNC
75 ret = vsnprintf(buf,
sizeof(buf), format, ap);
76 if (ret >= 0 && ret <
sizeof(buf))
78 ret = vsnprintf_doubling(
sizeof(buf), format, ap);