mdbx-windows: refine mdbx_vasprintf() to avoid dependency from CRT.

10 of 17 for https://github.com/leo-yuriev/libmdbx/issues/43

Change-Id: I95c4583c27503eb4e9221b212b34474dfb561e6d
This commit is contained in:
Leonid Yuriev 2018-10-14 10:35:53 +03:00
parent 80ccb31008
commit f49741b4f8

View File

@ -219,14 +219,7 @@ __cold void mdbx_panic(const char *fmt, ...) {
int mdbx_vasprintf(char **strp, const char *fmt, va_list ap) {
va_list ones;
va_copy(ones, ap);
#ifdef _MSC_VER
int needed = _vscprintf(fmt, ap);
#elif defined(vsnprintf) || defined(_BSD_SOURCE) || _XOPEN_SOURCE >= 500 || \
defined(_ISOC99_SOURCE) || _POSIX_C_SOURCE >= 200112L
int needed = vsnprintf(nullptr, 0, fmt, ap);
#else
#error FIXME
#endif
if (unlikely(needed < 0 || needed >= INT_MAX)) {
*strp = nullptr;
@ -245,12 +238,7 @@ int mdbx_vasprintf(char **strp, const char *fmt, va_list ap) {
return -1;
}
#if defined(vsnprintf) || defined(_BSD_SOURCE) || _XOPEN_SOURCE >= 500 || \
defined(_ISOC99_SOURCE) || _POSIX_C_SOURCE >= 200112L
int actual = vsnprintf(*strp, needed + 1, fmt, ones);
#else
#error FIXME
#endif
va_end(ones);
assert(actual == needed);